StitchAuthDelegate
public protocol StitchAuthDelegate : AnyObject
StitchAuthDelegate
is a protocol to be inherited when you need to take action on authentication events.
An instance of a StitchAuthDelegate
must be added to a StitchAuth
.
Note
This protocol uses an extension to provide default implementations. This is for your convenience, so you do not
have to implement every method here to satisfy the protocol requirements. This however does mean that if you plan
on subclassing your implementation of StitchAuthDelegate
, you may run into unexpected issues where the empty
default implementation is called instead of your subclass implementation. If this does happen in your code, see
this article
for more context and potential workarounds, or open an issue in our GitHub repository.
- Tag: StitchAuthDelegate
-
onAuthEvent(fromAuth:)
Default implementationCalled whenever a
StitchAppClient
performs an authentication event.Note
When this method is invoked by a
StitchAuth
for which this delegate is registered, the invocation will be dispatched to a non-main dispatch queue, so be sure to dispatch any UI operations back to the mainDispatchQueue
.Default Implementation
Declaration
Swift
func onAuthEvent(fromAuth: StitchAuth)
Parameters
fromAuth
The
StitchAuth
object that caused the authentication event. -
onUserAdded(auth:addedUser:)
Default implementationCalled whenever a user is added to the device for the first time. If this is as part of a login, this method will be called before
onUserLoggedIn
, andonActiveUserChanged
are called.Default Implementation
Declaration
Swift
func onUserAdded(auth: StitchAuth, addedUser: StitchUser)
Parameters
auth
The instance of
StitchAuth
where the user was added. It can be used to infer the current state of authentication.addedUser
The user that was added to the device.
-
onUserLoggedIn(auth:loggedInUser:)
Default implementationCalled whenever a user is logged in. This will be called before
onActiveUserChanged
is called.Note: if an anonymous user was already logged in on the device, and you log in with an
AnonymousCredential
, this method will not be called, as the underlyingStitchAuth
will reuse the anonymous user’s existing session, and will thus only triggeronActiveUserChanged
.Default Implementation
Declaration
Swift
func onUserLoggedIn(auth: StitchAuth, loggedInUser: StitchUser)
Parameters
auth
The instance of
StitchAuth
where the user was logged in. It can be used to infer the current state of authentication.loggedInUser
The user that was logged in.
-
onUserLinked(auth:linkedUser:)
Default implementationCalled whenever a user is linked to a new identity.
Default Implementation
Declaration
Swift
func onUserLinked(auth: StitchAuth, linkedUser: StitchUser)
Parameters
auth
The instance of
StitchAuth
where the user was linked. It can be used to infer the current state of authentication.linkedUser
The user that was linked to a new identity.
-
onUserLoggedOut(auth:loggedOutUser:)
Default implementationCalled whenever a user is logged out. The user logged out is not necessarily the active user. If the user logged out was the active user, then
onActiveUserChanged
will be called after this method. If the user was an anonymous user, that user will also be removed andonUserRemoved
will also be called.Default Implementation
Declaration
Swift
func onUserLoggedOut(auth: StitchAuth, loggedOutUser: StitchUser)
Parameters
auth
The instance of
StitchAuth
where the user was logged out. It can be used to infer the current state of authentication.loggedOutUser
The user that was logged out.
-
onActiveUserChanged(auth:currentActiveUser:previousActiveUser:)
Default implementationCalled whenever the active user changes. This may be due to a call to
StitchAuth.loginWithCredential
,StitchAuth.switchToUserWithId
,StitchAuth.logout
,StitchAuth.logoutUserWithId
,StitchAuth.removeUser
, orStitchAuth.removeUserWithId
. This may also occur on a normal request if a user’s session is invalidated and they are forced to log out.Default Implementation
Declaration
Swift
func onActiveUserChanged(auth: StitchAuth, currentActiveUser: StitchUser?, previousActiveUser: StitchUser?)
Parameters
auth
The instance of
StitchAuth
where the the active user changed. It can be used to infer the current state of authentication.currentActiveUser
The active user after the change.
previousActiveUser
The active user before the change.
-
onUserRemoved(auth:removedUser:)
Default implementationCalled whenever a user is removed from the list of users on the device.
Default Implementation
Declaration
Swift
func onUserRemoved(auth: StitchAuth, removedUser: StitchUser)
Parameters
auth
The instance of
StitchAuth
where the the user was removed. It can be used to infer the current state of authentication.removedUser
The user that was removed.
-
onDelegateRegistered(auth:)
Default implementationCalled whenever this delegate is registered for the first time. This can be useful to infer the state of authentication, because any events that occurred before the delegate was registered will not be seen by the delegate.
Default Implementation
Declaration
Swift
func onDelegateRegistered(auth: StitchAuth)
Parameters
auth
The instance of
StitchAuth
where the the delegate was registered. It can be used to infer the current state of authentication.