init
This commit is contained in:
38
src/lib/supertokens/client.ts
Normal file
38
src/lib/supertokens/client.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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!`);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user