The examples below create and pass a custom Token Store to handle storing the auth token in localstorage only, overriding the default client-side auth token handling of storing in both localstorage and cookie.
<html> <head> <title>Your Page Title Here</title> ... </head> <body> ... <passage-authapp-id="<PASSAGE_APP_ID>"></passage-auth> <scriptsrc="https://psg.so/web.js"defer></script> <script>// Implement Token Store and required methodsclassCustomTokenStoreextendsPassage.TokenStore {asyncgetAuthToken() {constlocalToken=localStorage.getItem("custom_auth_token");return localToken ??""; }asyncsetTokens(authResult) {localStorage.setItem("custom_auth_token",authResult.auth_token);if (authResult.refresh_token) {localStorage.setItem("custom_auth_token",authResult.refresh_token); }return; }asyncgetRefreshToken() {constrefreshToken=localStorage.getItem("custom_refresh_token");return refreshToken ??undefined; }asyncclearTokens() {localStorage.removeItem("custom_auth_token");return; } }// Create an instance of the Token StoreconstcustomTokenStore=newCustomTokenStore();// Pass the instance of the Token Store as a property on the Passage elementconstpassageAuth=document.querySelector("passage-auth");passageAuth.tokenStore = customTokenStore; </script> </body></html>
import { PassageAuth } from'@passageidentity/passage-react';import { TokenStore } from'@passageidentity/passage-js';exportconstPassageAuthElement:React.FC= () => {// Implement Token Store and required methodsclassCustomTokenStoreextendsTokenStore {asyncgetAuthToken() {constlocalToken=localStorage.getItem('custom_auth_token');return localToken ??''; }asyncsetTokens(authResult:string) {localStorage.setItem('custom_auth_token',authResult.auth_token);if (authResult.refresh_token) {localStorage.setItem('custom_auth_token',authResult.refresh_token); }return; }asyncgetRefreshToken() {constrefreshToken=localStorage.getItem('custom_refresh_token');return refreshToken ??undefined; }asyncclearTokens() {localStorage.removeItem('custom_auth_token');return; } }// Create an instance of the CustomTokenStore classconstcustomTokenStore=newCustomTokenStore();// Pass the instance in as a prop to the Passage elementreturn ( <> <PassageAuthtokenStore={customTokenStore} /> </> );};