Authentication Token for Secure Components
Acquire a tokenised password
Before advancing to user authentication, it's crucial to obtain a tokenised password. Achieve this by mounting a password component and providing your plaintext value. The value will then be returned in a tokenised format. For additional details on tokenising values with the Password Component, refer to this resource.
Now that you have the tokenised password, you can authenticate the user using the tokenised password.
You must perform this step from within your application.
After a successful login you will receive the user authentication token as token
in the response. You must then use
this token to authenticate the user in all subsequent API calls.
Setting the user token
The obtained token
should subsequently be supplied to the setUserToken
function, which is utilized for authenticating future requests.
weavrComponents.setUserToken('Bearer ' + {{ user_token }})
.then(() => {
// User token is set and secure components can be created and mounted
})
.catch((err) => {
// Error while setting user token. Check 'err' for more info
})
Please be aware that the component's state resets during reloads. Therefore, it is advisable to perform the aforementioned steps upon each reload to guarantee continuous access to the latest authentication token for the components. Additionally, update the authentication token if it undergoes any changes during the session.
Resetting the user token
To manually reset the user token stored within the components, invoke the resetUserToken
function. This action will clear the existing token, enabling a fresh token to be set without requiring a full page reload.
weavrComponents.resetUserToken();