Called whenever the active user changes.
Any of the following functions may trigger this event:
This may also occur on a CRUD operation or Stitch Function call if a user's session is invalidated and they are forced to log out.
The instance of StitchAuth where the active user changed. It can be used to infer the current state of authentication.
The active user after the change.
The active user before the change.
The instance of StitchAuth where the event happened. It should be used to infer the current state of authentication.
Called whenever this listener is registered for the first time. This can be useful to infer the state of authentication, because any events that occurred before the listener was registered will not be seen by the listener.
The instance of StitchAuth where the listener was registered. It can be used to infer the current state of authentication.
Called 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 and onActiveUserChanged are called.
The instance of StitchAuth where the user was added. It can be used to infer the current state of authentication.
The user that was added to the device.
Called whenever a user is linked to a new identity.
The instance of StitchAuth where the user was linked. It can be used to infer the current state of authentication.
The user that was linked to a new identity.
Called whenever a user is logged in. This will be called before onActiveUserChanged is called.
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 underlying StitchAuth will reuse the anonymous user's existing session, and will thus only trigger onActiveUserChanged.
The instance of StitchAuth where the user was logged in. It can be used to infer the current state of authentication.
The user that was logged in.
Called whenever a user is logged out.
The user logged out is not necessarily the active user.
If the user who 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 and onUserRemoved will also be called.
The instance of StitchAuth where the user was logged out. It can be used to infer the current state of authentication.
The user that was logged out.
Called whenever a user is removed from the list of users on the device, i.e. with StitchAuth.removeUser or StitchAuth.removeUserWithId.
Anonymous users are automatically removed when logged out.
The instance of StitchAuth where the user was removed. It can be used to infer the current state of authentication.
The user that was removed.
Generated using TypeDoc
StitchAuthListener
StitchAuthListener is an interface for taking action whenever a particular StitchAppClient's authentication state changes.
Implement the methods in this interface to handle these events. You can register your listener with StitchAuth using StitchAuth.addAuthListener.
StitchAuth calls registered listeners when:
Some actions may trigger multiple events. For instance. Logging into a user for the first time will trigger onUserAdded, onUserLoggedIn, and onActiveUserChanged.
Note
The callbacks in this interface are called asynchronously. This means that if many auth events are happening at the same time, events that come in may not necessarily reflect the current state of authentication. In other words, although these methods will be called after events happen, those events may be stale by the time the listener method is called. Always check the state of StitchAuth object for the true authentication state.
Example
// In this example, a custom StitchAuthListener is defined and registered: const stitchClient = Stitch.defaultAppClient // Define the listener const myAuthListener = { onUserAdded: (auth, addedUser) => { console.log('onUserAdded:', addedUser.profile) }, onUserLoggedIn: (auth, loggedInUser) => { console.log('onUserLoggedIn:', loggedInUser.profile) }, onActiveUserChanged: (auth, currentActiveUser, previousActiveUser) => { console.log('onActiveUserChanged:', currentActiveUser, previousActiveUser) }, onUserLoggedOut: (auth, loggedOutUser) => { console.log('onUserLoggedOut:', loggedOutUser.profile) }, onUserRemoved: (auth, removedUser) => { console.log('onUserRemoved:', removedUser.profile) }, onUserLinked: (auth, linkedUser) => { console.log('onUserLinked:', linkedUser.profile) }, onListenerRegistered: (auth) => { console.log('onListenerRegistered') }, } // Register the listener const {auth} = stitchClient auth.addAuthListener(myAuthListener) // Console: // onListenerRegistered const user = await auth.loginWithCredential(new UserPasswordCredential('user', 'password')) // Console: // onUserAdded // onUserLoggedIn // onActiveUserChanged await auth.logout() // Console: // onUserLoggedOut // onActiveUserChanged await auth.removeUserWithId(user.id) // Console: // onUserRemoved
See Also