Situation:
- user is loggen in with Sing In with Apple
- session were removed from database while client app was not running
- client app launch and upon fetch gets Invalid session error
- UI leads to login screen where the apple authentication runs again and triggers
User.apple.login(user: appleIDCredential.user, identityToken: token) { result in ... }
Issue:
-
result
is.failure
with error 209 - Invalid session token
I believe it is because the User.current
is not nil. But I would like just to login again to create new Session
object in the database and resume using the client. So User.logout()
is not a good workaround as it deletes data in User.current
.
Is there any way how to re-login an apple sign in method?
Through breakpoints it goes through:
internal func linkCommand(body: SignupLoginBody) -> API.NonParseBodyCommand<SignupLoginBody, Self> {
var body = body
Self.current?.anonymous.strip()
if var currentAuthData = Self.current?.authData {
if let bodyAuthData = body.authData {
bodyAuthData.forEach { (key, value) in
currentAuthData[key] = value
}
}
body.authData = currentAuthData
}
return API.NonParseBodyCommand<SignupLoginBody, Self>(method: .PUT,
path: endpoint,
body: body) { (data) -> Self in
let user = try ParseCoding.jsonDecoder().decode(UpdateSessionTokenResponse.self, from: data)
Self.current?.updatedAt = user.updatedAt
Self.current?.authData = body.authData
guard let current = Self.current else {
throw ParseError(code: .unknownError, message: "Should have a current user.")
}
if let sessionToken = user.sessionToken {
Self.currentContainer = .init(currentUser: current,
sessionToken: sessionToken)
}
Self.saveCurrentContainerToKeychain()
return current
}
}
with body:
(ParseSwift.SignupLoginBody) body = {
username = nil {
some = {
_guts = {
_object = (_countAndFlagsBits = Swift.UInt64 @ 0x000000016f8cd990, _object = 0x0000000000000000)
}
}
}
password = nil {
some = {
_guts = {
_object = (_countAndFlagsBits = Swift.UInt64 @ 0x000000016f8cd9a0, _object = 0x0000000000000000)
}
}
}
authData = 1 key/value pair {
some = 1 key/value pair {
_variant = {
object = (rawValue = 0x00000001143a57d0)
}
}
}
}
printing out values I can confirm that body.authData
stays “apple” and has the new apple token. The error is returned by the execution function:
// MARK: Asynchronous Execution
func executeAsync(options: API.Options,
completion: @escaping(Result<U, ParseError>) -> Void) {
switch self.prepareURLRequest(options: options) {
case .success(let urlRequest):
URLSession.parse.dataTask(with: urlRequest, mapper: mapper) { result in
switch result {
case .success(let decoded):
completion(.success(decoded))
case .failure(let error):
completion(.failure(error))
}
}
case .failure(let error):
completion(.failure(error))
}
}
Therefore I am not sure if this is a missing functionality on the server side or did I missed some SDK logic.
Help would be greatly appreciated! Thank you!