Open marcusdiy opened 4 years ago
Uh ok seems the expected behavior. https://developer.apple.com/forums/thread/121496 But I think some kind of internal plugin cache would be better. What do you think?
I've faced same problem few days ago. personally I use NativeStorage to cache user's email. It just work but Idk it is proper way.
Using NativeStorage doesn't suffice: if the user uninstalls and reinstalls the app (thus clearing NativeStorage), the device still stores the Apple Sign In configuration from the first time. Hence, on reinstall, it will be treated as just another login and, since NativeStorage was cleared), the app has no way of every retrieving the email again. The user would have to manually go into Settings->Apple ID->Password & Security->Apps Using Apple ID->{appName} and then tap on "Stop Using Apple ID". This is probably not the best way to handle this.
The only reliable solution is to communicate the token to your backend servers, which then communicates to Apple servers, where you get the email on every request: https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens
Not sure if it is valid, secure or even possible (i mean without rejection in App Store review) to communicate with Apple REST API directly from the application, without a intermediate backend.
window.cordova.plugins.SignInWithApple.signin({ requestedScopes: [0, 1] }, function (succ) { let jwt = succ.identityToken; let decoded = jwt_decode(jwt); console.log(decodedl); console.log(decoded.email); }, function (err) { console.error(err) console.log(JSON.stringify(err)) } )
@zhicheng-Fu Thanks, this addresses this issue perfectly!
window.cordova.plugins.SignInWithApple.signin({ requestedScopes: [0, 1] }, function (succ) { let jwt = succ.identityToken; let decoded = jwt_decode(jwt); console.log(decodedl); console.log(decoded.email); }, function (err) { console.error(err) console.log(JSON.stringify(err)) } ) This should be the accepted answer.
for jwt_decode use this https://www.npmjs.com/package/jwt-decode
Hi, Is it normal that the user email is showed only on the first sign up? ...on the following logins it will be just and empty string. Thanks