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.
If hasRedirectResult is true, completes the OAuth2 login previously started by loginWithRedirect.
Checks whether or not an external login process previously started by loginWithRedirect has redirected the user to this page.
Stitch will have this information available right after initialization.
Call this method before calling handleRedirectResult if you want to avoid errors.
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.
Authenticates the client as a MongoDB Stitch user using the provided StitchRedirectCredential.
This method will redirect the user to an OAuth2 login page where the login is handled externally. That external page will redirect the user back to the page specified in the redirect credential. To complete the login, that page will need to handle the redirect by calling handleRedirectResult.
For usage examples, see Facebook Authentication and Google Authentication.
The StitchRedirectCredential 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, loginWithCredential or loginWithRedirect.
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
Refresh a user's custom data field.
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. Depending on which Authentication Provider you are using, use loginWithCredential or loginWithRedirect to log in.
Once logged in, StitchAuth.user is a StitchUser object that can be examined for user profile and other information.
Login state can persist across browser sessions. Therefore, a StitchAppClient's StitchAuth instance may already contain login information upon initialization.
In the case of OAuth2 authentication providers, StitchAuth may also initialize with the result of a previous session's request to loginWithRedirect. The redirect result can be checked with hasRedirectResult and handled with handleRedirectResult.
To log out, use logout.
Examples
For an example of loginWithRedirect, see Facebook Authentication.
// 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