I am trying to implement sign in with apple to Realm. I already did the configuration from the docs: https://www.mongodb.com/docs/atlas/app-services/authentication/apple/#std-label-apple-id-authentication
Now I am trying to add the sign in with Apple button and the flow.
The login button on SwiftUI:
SignInWithAppleButton(.signIn, onRequest: { request in
isLoggingIn = true
request.requestedScopes = [.email]
}, onCompletion: { result in
switch result {
case .success(let authResults):
guard let credentials = authResults.credential as? ASAuthorizationAppleIDCredential,
let identityToken = credentials.identityToken,
let identityTokenString = String(data: identityToken, encoding: .utf8) else { return }
repo.loginwithApple(appleTokenIDString: identityTokenString) { user, error in
}
case .failure(let error):
isLoggingIn = false
}
})
repo.loginwithApple
calls the method from the shared kotlin repository:
suspend fun loginwithApple(appleTokenIDString: String): User {
var credentials = Credentials.apple(idToken = appleTokenIDString)
return appService.login(credentials = credentials)
}
Whenever I try to do the login with the apple sign in button I get this exception:
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SharedRealmRepo loginwithAppleAppleTokenIDString:completionHandler:]: unrecognized selector sent to instance 0x281fe4960'
terminating with uncaught exception of type NSException
Any idea why the exception happens?
It looks like removing the Output Files from XCode will solve the issue, but I do not know why.
Maybe someone has a explanation of why this happens. The output files will not let the realm repo re-build?