Λ C Ξ L X R D
05/03/2022, 11:10 PMjs
import "https://cdn.jsdelivr.net/gh/supertokens/supertokens-website/bundle/bundle.js"
supertokens.init(
{
apiDomain: "http://localhost:8000",
apiBasePath: "/auth",
onHandleEvent: (context) => {
if (context.action === "UNAUTHORISED") {
// called when the user doesn't have a valid session but made a request that requires one
// NOTE: This event can fire multiple times
if (context.sessionExpiredOrRevoked) {
// the sessionExpiredOrRevoked property is set to true if the current call cleared the session from storage
// this happens only once, even if multiple tabs sharing the same session are open, making it useful for analytics purposes
fetch("auth/session/refresh", {method: "POST"}).then(r =>{
if (r.status === 200) {
console.log("Session refreshed")
} else {
console.log("Session refresh failed")
}
})
}
}
}
});