Apple users cannot sign in with service ID but have no problems on iOS app

Viewed 296

EDIT

For everyone who has had trouble with this: it wasn't anything related to how I set up the service ID. It was the user object in the response from apple which caused a type error, that somehow was thrown without a message.

Normally the user object should only be present when the user signs in the first time on an application. If there is a user, who created an account a few months ago, the response contains an empty user object instead of none. So I did check if there was a user object, but I didn't check if it was empty or not, which caused the error (see the if-block below).

Original Question

I have a problem syncing apple users on a platform between the app id, which is used for our iOS app and the service id, which is used for our web app.

Situation: We have implemented 'sign in with apple id' on both an iOS app and a NuxtJS web app. Users have been able to register on our iOS app since apple released the feature and now we launched our web app. Therefor we created a new service id, which is connected to the primary app id of our iOS app. I have primarily used this tutorial alongside with the official apple docs to implement the sign in button on the web app.

Problem: Users who registered via apple id before we launched the web app, cannot log in on our web app. The iOS app still works fine. New users, who register either on our app or the web app have no problems at all.

So somehow, the new users can login with the new service id and the primary app id, but users who where already registered with the app id can only login on the app. Sadly I did not figure out yet, how to reproduce this. Would really appreciate any hint, to what might be the cause of this.

I use the AppleJS SDK with NuxtJS and Typescript.

This is how I set up the apple sign in in mounted():

const windowLocal = window as any
windowLocal.AppleID.auth.init({
  clientId: process.env.APPLE_CLIENT_ID,
  scope: 'email name',
  redirectURI: process.env.APPLE_REDIRECT_URI,
  state: 'init',
  usePopup: true
})

This is the apple login method:

try {
  const result = await windowLocal.AppleID.auth.signIn()
  const appleUser = jwt.decode(result.authorization.id_token, {
    complete: true
  }) as any
  this.appleUserId = appleUser.payload.sub
  this.email = appleUser.payload.email
  this.appleCode = result.authorization.code

  if (result.user) {
    this.firstName = result.user.name.firstName
    this.lastName = result.user.name.lastName
  } else {
    this.showNamePrompt = true
  }

  this.registerApple() // sends credentials to our backend
} catch (error) {
  eventModule.newError('error.login.apple')
}
0 Answers
Related