38 lines
989 B
TypeScript
38 lines
989 B
TypeScript
import SuperTokens from 'supertokens-web-js';
|
|
import Session from 'supertokens-web-js/recipe/session';
|
|
import Passwordless from 'supertokens-web-js/recipe/passwordless';
|
|
import { appInfo } from './config';
|
|
import { logger } from './';
|
|
|
|
export const frontendConfig = () => {
|
|
return {
|
|
appInfo,
|
|
recipeList: [
|
|
Passwordless.init(),
|
|
Session.init({
|
|
tokenTransferMethod: "cookie",
|
|
sessionTokenBackendDomain: undefined,
|
|
|
|
preAPIHook: async (context) => {
|
|
context.requestInit.credentials = "include";
|
|
return context;
|
|
},
|
|
})
|
|
]
|
|
};
|
|
}
|
|
|
|
let initialized = false;
|
|
export function ensureSuperTokensFrontend() {
|
|
if (typeof window === 'undefined') return;
|
|
|
|
if (!initialized) {
|
|
SuperTokens.init(frontendConfig());
|
|
initialized = true;
|
|
logger.info("Initialized");
|
|
|
|
Session.doesSessionExist().then(exists => {
|
|
logger.info(`Session does${exists ? '' : 'NOT'} exist on load!`);
|
|
});
|
|
}
|
|
} |