When using Outseta's Quick Start embed script, you have access to access to the decoded JWT token through the accessToken.set
event, Outseta.getJwtPayload()
or the user's profile through the Outseta.getUser()
.
Check out a demo:
👉 Access user info client-side with VanillaJS
Outseta.getUser()
Returns the currently logged-in user. This method returns a JavaScript Promise that resolves when the user is logged in, and their information has been retrieved from the server. The returned user object also has an update(data)
method, which can be used to update user properties.
Outseta.getUser().then((profile) => {
console.log("PersonUid:", profile.Uid);
console.log("Email:", profile.Email);
console.log("AccountUid:", profile.Account.Uid);
});
The passed profile object will contain a lot of data, including first name, last name, subscription status account information, and much more. After adding the above snippet to the head element on your site, we encourage you to check out the console to see the complete data set.
Outseta.getJwtPayload()
Returns the currently stored JWT payload. Aka. the decoded access token of the authenticated user. The access token is regenerated on every login and some profile-embed events, meaning it will not always have the latest state. Use Outseta.getUser()
when you must have the latest data.
Outseta.getJwtPayload().then((payload) => {
if(payload) {
console.log("PersonUid:", payload.sub);
console.log("Email:", payload.email);
console.log("AccountUid:", payload["outseta:accountUid"]);
// For the full payload reference: The JWT Access Token
}
});
accessToken.set
The accessToken.set event is triggered when the access token (an encoded JWT) is set with Outseta.setAccessToken(accessToken)
, read from the storage method configured, or when the node code module reads it from the URL.
The decodes JWT includes some user info and is available before the entire profile is returned from the server in Outseta.getUser()
.
Outseta.on('accessToken.set', (payload) => {
console.log("PersonUid:", payload.sub);
console.log("Email:", payload.email);
console.log("AccountUid:", payload["outseta:accountUid"]);
// For the full payload reference: The JWT Access Token
});