Whether or not there is a currently logged in active user of this StitchAuth.
A StitchUser object representing the currently logged in, active user,
or undefined
if there is no logged in active user.
Registers a StitchAuthListener with the client.
The listener to be triggered when an authentication event occurs on this auth object.
Returns a list of all users who have logged into this application, except those that have been removed manually and anonymous users who have logged out.
The list of users is a snapshot of the state when listUsers() is called. The [[StitchUsers]] in this list will not be updated if, e.g., a user's login state changes after this is called.
Logs in as a StitchUser using the provided StitchCredential.
The StitchCredential to use when logging in.
Logs out the currently authenticated active user and clears any persisted authentication information for that user.
There will be no active user after this logout takes place, even if there are other logged in users. Another user must be explicitly switched to using switchToUserWithId or loginWithCredential.
Logs out the user with the provided id.
The promise rejects with an exception if the user was not found.
Because anonymous users are deleted after logout, this method is equivalent to removeUserWithId for anonymous users.
the id of the user to log out
Unregisters a listener.
Logs out the active user and removes that user from the list of all users associated with this application as returned by StitchAuth.listUsers.
Removes the user with the provided id from the list of all users associated with this application as returned by StitchAuth.listUsers.
If the user was logged in, the user will be logged out before being removed.
The promise rejects with an exception if the user was not found.
the id of the user to remove
Switches the active user to the user with the specified id. The user must exist in the list of all users who have logged into this application, and the user must be currently logged in, otherwise this will throw a StitchClientError.
the id of the user to switch to
Generated using TypeDoc
StitchAuth
StitchAuth represents and controls the login state of a StitchAppClient.
Login is required for most Stitch functionality. Check which Authentication Provider you are using and use loginWithCredential to log in.
For OAuth2 login (e.g. Google, Facebook), you must obtain a server auth code yourself and pass it to the relevant StitchCredential. One approach is to use a third party module, e.g. install google-auth-library and use it to get the auth code to pass to GoogleCredential.
Once logged in, StitchAuth.user is a StitchUser object that can be examined for user profile and other information.
To log out, use logout.
Example
// Previously: // const stitchAppClient = Stitch.initializeDefaultAppClient('your-stitch-app-id') // Log in with anonymous credential stitchAppClient.auth .loginWithCredential(new AnonymousCredential()) .then((user) => { console.log(`Logged in as anonymous user with id: ${user.id}`) }) .catch(console.error)
See Also