The Auth class is a crucial component of the Descope SDK, handling key user authentication operations.
This class is designed to execute essential functions such as fetching
user details (me), refreshing a session (refreshSession), and logging out a user (logout).
Functions can take an optional refresh token as a parameter.
Retrieves information about the currently authenticated user. This method is used when you need to fetch or display user-related data in your application.
This function returns the following details:
loginIds: An array of loginIds associated to the user.
userId: The user's unique Descope generated userId
verifiedEmail: Boolean whether the email address for the user has been verified.
verifiedPhone: Boolean whether the phone number for the user has been verified.
picture: The base64 encoded image if the user has an image associated to them.
roleNames: An array of roles associated to the user.
userTenants: An array of tenant names and IDs associated to the user.
createTime: The time that the user was created.
totp: Boolean wether the user has TOTP login associated with it.
saml: Boolean wether the user has SAML login associated with it.
oauth: Boolean wether the user has OAuth login associated with it.
For a case that the browser has a valid refresh token on storage/cookie,
the user should get a valid session token (e.i. user should be logged-in).
For that purpose, it is common to call the refresh function after sdk initialization.
Note: Refresh return a session token, so if the autoRefresh was provided, the sdk will
automatically continue to refresh the token
Logs out the currently authenticated user. This method invalidates the user's current JWT tokens and ends their session. This function is typically used when the user chooses to log out of your application.
This will sign the user out of all the devices they are currently signed-in with.
Successfully executing this endpoint will invalidate all user's refresh tokens.
Response will include all user tokens and fields empty, so client will remove cookies as well.
Providing tenant will initialize the flow with the tenant associated. This is crucial for B2B(Business To Business)
implementation as Descopers need to segregate their customers to tenant specific configuration such as SSO and attribute mapping.