Hello everyone.
We have the app which uses anonymous user authentication and also provides means for users to authenticate later.
We have following logic: when anonymous user authenticates with Apple ID, we try to link anonymous user to that Apple ID. If user already exists with that Apple ID, then we attempt to log in with that Apple ID:
do {
let _ = try await mergeAnon?.linkUser(credentials: credentials)
} catch {
let nsError = error as NSError
if nsError.domain == RLMAppErrorDomain && nsError.code == 2 {// how to catch "a user already exists with the specified provider"?
let _ = try await app.login(credentials: credentials)
} else {
throw error
}
}
The problem is that we don’t know how to match the exact “a user already exists with the specified provider” error. Different errors may be thrown from the linkUser(…) call, but they have the same domain and error code. Here is the description of 2 different error we catch here:
1: Error we try to match (catch):
Error Domain=io.realm.app Code=2 "a user already exists with the specified provider" UserInfo=(Server Log URL=(...), NSLocalizedDescription=a user already exists with the specified
provider, HTTP Status Code=401}
2: Error we don’t need to match (catch):
Error Domain=io.realm.app Code=2 "invalid session:
access token expired" UserInfo=(Server Log URL=(...), NSLocalizedDescription=invalid
session: access token expired, HTTP Status Code=401}
Both have userInfo with 3 key/value pairs, both share HTTP Status Code 401 (which is no help), but they have distinct localised descriptions.
Obviously there is some error subcode missing in userInfo, which we would like use to match our target error. And to match error based on localizedDescription would be a terrible idea.
Could someone confirm this is a swift SDK issue so we could bump it somehow to become fix in future update?
Or maybe we’re missing something, like specific Error type to catch?