Skip to main content

Token Management

From the moment you init app with a token, app takes care of it and updates token automatically, eventually making initial token invalid. It means that you can't use single token for different user sessions reliably.

You can issue a new token for every session but it will cause a token overuse.

The better approach is to issue a new token only when previous is expired or invalidated.

app.onTokenUpdate method is just for that.

Example

import { app } from '@3deye-toolkit/core';

// Token is stored in memory by default but you can alter that behavior
// by providing storage of your choice (like `sessionStorage` for example)
// in `tokenStorage` config option.
const storage = sessionStorage;

app.init({ token, storage });

// Subscribe to token updates
// NOTE: app has to be inited by that moment or the method will throw an error
const disposeTokenSubscription = app.onTokenUpdate(token => {
if (!token) {
console.log('user is signed out due token removal or invalidation');
return;
}

// do smth with the token
});



// call it to prevent memory leak when the subscription
// is no more needed or before app disposal
disposeTokenSubscription();