From 6fe9b036d44e7af80b126e3aff0f5c8a1cdaedca Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 22 Aug 2024 10:16:49 -0700 Subject: [PATCH] User Manger - updates to login --- .../Source/OneSignalUserManagerImpl.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index f5606b742..624beeaf4 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -308,6 +308,10 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { if let user = _user { guard user.identityModel.externalId != externalId || externalId == nil else { OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignalUserManager.createNewUser: not creating new user due to logging into the same user.)") + if externalId != nil, token != nil { + // save the jwtToken, it can be updated + user.identityModel.jwtBearerToken = token + } return user } } @@ -386,17 +390,19 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { } OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignalUserManager internal _login called with externalId: \(externalId ?? "nil")") - // If have token, validate token. Account for this being a requirement. - // Logging into an identified user from an anonymous user + // Logging into an identified user from an anonymous user, if JWT is not ON if let externalId = externalId, let user = _user, - user.isAnonymous { + user.isAnonymous, + jwtConfig.isRequired != true + { user.identityModel.jwtBearerToken = token identifyUser(externalId: externalId, currentUser: user) return self.user } - // Logging into anon -> anon, identified -> anon, identified -> identified, or nil -> any user + // JWT Off: Logging into anon -> anon, identified -> anon, identified -> identified, or nil -> any user + // JWT On: All return createNewUser(externalId: externalId, token: token) }