Support Topics Documentation Slack YouTube Blog

Not existing user token error when Login With Apple

Hi

I am experiencing an issue when I use Login With Apple feature.

I have deleted all objects on User table (I was testing user data migration from iCloud to backendless) and after that I receive:

Error: Not existing user token - B1C0F354-D8BA-4F55-AFA7-F91D4D906034. Relogin user to update your user token

when I execute the following code:

private func signInWithExistingAccount(credential: ASAuthorizationAppleIDCredential) {
    if let identityToken = credential.identityToken,
       let tokenString = String(data: identityToken, encoding: .utf8) {
        AppleAuth.shared.login(token: tokenString, responseHandler: { loggedInUser in
            Backendless.shared.userService.currentUser = (loggedInUser as! BackendlessUser)
            self.signInSucceeded(.success(credential.user))
        }, errorHandler: { fault in
            print("Error: \(fault.message ?? "")")
            self.signInSucceeded(.failure(fault))
        })
    } else { self.signInSucceeded(.failure(ErroresCK.notSignediCloud))}
}

Any idea how I can manage this?

Thank you

PS here the class called above:

class AppleAuth: NSObject {
    static let shared = AppleAuth()
    private let serviceName = "AppleAuth"

    func login(token: String, responseHandler: ((Any?) -> Void)!, errorHandler: ((Fault) -> Void)!) {
        let parameters = token
        Backendless.shared.customService.invoke(serviceName: serviceName, method: "login", parameters: parameters, responseHandler: responseHandler, errorHandler: errorHandler)
    }
}

Hello @Alejandro_Cuartas_Fernandez,

Could you please provide you APP ID?
Also as far as you remember current user after login, he’s token is saved on the device and the error may occur after you delete the user record from database but token is still exists on your device.
Please logout before the login to refresh token:

Backendless.shared.userService.logout(responseHandler: {
	AppleAuth.shared.login(token: tokenString, responseHandler: { loggedInUser in
    	Backendless.shared.userService.currentUser = (loggedInUser as! BackendlessUser)
   		print("Signed in")
    }, errorHandler: { fault in
    	print("Apple Login Error: \(fault.message ?? "")")
    })
}, errorHandler: { fault in
    print("Logout Error: \(fault.message ?? "")")
})

Regards,
Olha

Thank you for your answer Olha!!!

It does work after logout

Regards