Methods
(static) changeOrganisation(organisation, options)
- Source:
Manually set current user session
Example
sdk.auth.changeOrganisation('61eca4746971e75c1fc670cf');
// Current user session will be automatically updated
const newSession = await sdk.auth.changeOrganisation('61eca4746971e75c1fc670cf', {disableAutoAuthentication:true});
// Current user session will not be updated
sdk.auth.set(newSession);
Parameters:
| Name |
Type |
Description |
organisation |
String
|
Object
|
The id of the organisation to switch into |
options |
Object
|
Additional options
Properties
| Name |
Type |
Description |
disableAutoAuthentication |
Boolean
|
By default when switching organisation, the current user session
will be updated to reflect a session in the new organisation, you can use this option to disable that behavior and instead return the
user session without dispatching any events |
|
(static) ensureValidToken(forceRefresh)
- Source:
This function forces a check to ensure that the current access token has not expired.
If the token has expired, the user session will be refreshed with a new token.
Example
// Check to ensure that the current access token is valid
sdk.auth.ensureValidToken();
// Force the token to be refreshed, even if the current token in use has not yet expired.
sdk.auth.ensureValidToken(true);
Parameters:
| Name |
Type |
Description |
forceRefresh |
Boolean
|
Whether to force the current token to be refreshed, even if it has not yet expired. |
(static) getCurrentToken()
- Source:
Retrieves the current access token. If the user is authenticated
the response will be the current user's access token, otherwise will fall back to the
applications token.
Example
const currentAccessToken = sdk.auth.getCurrentToken();
(static) getCurrentUser()
- Source:
Retrieves the current user session
Example
const me = sdk.auth.getCurrentUser();
(static) impersonate(persona, options)
- Source:
Impersonate another user within your organisation
Example
sdk.auth.impersonate('61eca4746971e75c1fc670cf');
// Current user session will be automatically updated
const newSession = await sdk.auth.impersonate('61eca4746971e75c1fc670cf', {disableAutoAuthentication:true});
// Current user session will not be updated
sdk.auth.set(newSession);
Parameters:
| Name |
Type |
Description |
persona |
String
|
Object
|
The id of the user persona you want to impersonate |
options |
Object
|
Additional options
Properties
| Name |
Type |
Description |
disableAutoAuthentication |
Boolean
|
By default when impersonating a user, the current user session
will be updated automatically to reflect the new session, you can use this option to disable that behavior and instead return the
new impersonation user session without dispatching any events |
|
(static) login(credentials, options)
- Source:
Login and authenticate as a user
Example
const credentials = {
email:'me@email.com',
password:'******',
mfa:'1234',
}
sdk.auth.login(credentials);
// Current user session will be automatically updated
const newSession = await sdk.auth.login(credentials, {disableAutoAuthentication:true});
// Current user session will not be updated
sdk.auth.set(newSession);
Parameters:
| Name |
Type |
Description |
credentials |
Object
|
The credentials used to login
Properties
| Name |
Type |
Description |
email |
String
|
The email address to login to |
password |
String
|
The password to login with |
mfa |
String
|
The MFA (Multi Factor Authentication) code |
|
options |
Object
|
Additional options
Properties
| Name |
Type |
Description |
disableAutoAuthentication |
Boolean
|
By default when logging in the current user session
will be updated automatically to reflect the new session, you can use this option to disable that behavior and instead return the
session that was logged in to without dispatching any events |
|
(static) logout()
- Source:
Clear the current user session from memory and erase all caches
Example
sdk.auth.logout();
(static) retrieveUserFromResetToken(resetToken, options)
- Source:
Retrieve user session through use of a valid reset token,
Reset tokens are short lived tokens that can be generated when a user has forgotten their password or their
password has been reset by an administrator
Example
const resetToken = 'XXX-324623-$$...';
// Retrieve the user session by providing a reset token
const user = await sdk.auth.retrieveUserFromResetToken(resetToken);
Parameters:
| Name |
Type |
Description |
resetToken |
String
|
The token to use to authenticate |
options |
Object
|
Additional options for the request |
(static) sendResetPasswordRequest(body)
- Source:
This function allows a reset token to be generated and emailed to the requesting user
allowing them to modify their user details
Example
const resetToken = 'XXX-324623-$$...';
// Retrieve the user session by providing a reset token
const user = await sdk.auth.retrieveUserFromResetToken(resetToken);
Parameters:
| Name |
Type |
Description |
body |
Object
|
Details for the reset request
Properties
| Name |
Type |
Description |
email |
String
|
The email of the user to generate a token for |
|
(static) set(user, parameters, stopDispatch)
- Source:
Manually set current user session
Example
const userSession = {_id:'61eca4746971e75c1fc670cf', firstName:'Daffy', lastName:'Duck' ...};
sdk.auth.set(userSession);
Parameters:
| Name |
Type |
Description |
user |
Object
|
The user session object to set as the current user session |
parameters |
Object
|
Additional parameters to dispatch |
stopDispatch |
Boolean
|
Whether to supress dispatching a 'change' event. |
(static) sync()
- Source:
A useful function to sync the current user session with the server.
Example
// Makes request to the API and updates the current user session to match the response
sdk.auth.sync();
(static) updateUserWithToken(resetToken, body, options)
- Source:
Update a user's credentials through use of a reset token
Example
const resetToken = 'XXX-324623-$$...';
// Retrieve the user session by providing a reset token
const user = await sdk.auth.retrieveUserFromResetToken(resetToken);
Parameters:
| Name |
Type |
Description |
resetToken |
String
|
The token to use to authenticate |
body |
Object
|
Updates to be made to the user |
options |
Object
|
Additional options for the request
Properties
| Name |
Type |
Description |
disableAutoAuthentication |
Boolean
|
By default the current user session
will be updated automatically to reflect the new updated session, you can use this option to disable that behavior
and instead return the result without dispatching any events |
|