Skip to content

Commit 1824c2f

Browse files
committed
logging out of anonymous user is a no-op
* As discussed in design forum, calling logout multiple times should result in a no-op. * Note that states can carry over.
1 parent 7af3f09 commit 1824c2f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,14 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
322322
}
323323

324324
/**
325-
The SDK needs to have a user at all times, so this method will create a new anonymous user.
325+
The SDK needs to have a user at all times, so this method will create a new anonymous user. If the current user is already anonymous, calling `logout` results in a no-op.
326326
*/
327327
@objc
328328
public func logout() {
329+
guard user.identityModel.externalId != nil else {
330+
OneSignalLog.onesignalLog(.LL_DEBUG, message: "OneSignal.User logout called, but the user is currently anonymous, so not logging out.")
331+
return
332+
}
329333
prepareForNewUser()
330334
_user = nil
331335
createUserIfNil()

0 commit comments

Comments
 (0)