init
This commit is contained in:
42
src/lib/supertokens/server.ts
Normal file
42
src/lib/supertokens/server.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import SuperTokens from "supertokens-node";
|
||||
import Session from "supertokens-node/recipe/session";
|
||||
import { TypeInput } from "supertokens-node/types";
|
||||
import Dashboard from "supertokens-node/recipe/dashboard";
|
||||
import UserRoles from "supertokens-node/recipe/userroles";
|
||||
import { appInfo } from "./config";
|
||||
import PasswordlessDevelopmentMode from "./recipes/passwordless-development-mode";
|
||||
import { logger } from "./";
|
||||
|
||||
export const backendConfig = (): TypeInput => {
|
||||
return {
|
||||
framework: 'custom',
|
||||
supertokens: {
|
||||
connectionURI: import.meta.env.VITE_SUPERTOKENS_URI || "https://try.supertokens.io",
|
||||
},
|
||||
appInfo,
|
||||
recipeList: [
|
||||
PasswordlessDevelopmentMode.init(),
|
||||
Session.init({
|
||||
cookieSameSite: "lax",
|
||||
cookieSecure: process.env.NODE_ENV === 'production',
|
||||
cookieDomain: process.env.NODE_ENV === 'production' ? ".example.com" : undefined,
|
||||
antiCsrf: process.env.NODE_ENV === 'production' ? "VIA_TOKEN" : "NONE",
|
||||
|
||||
// Debug only
|
||||
exposeAccessTokenToFrontendInCookieBasedAuth: true,
|
||||
}),
|
||||
Dashboard.init(),
|
||||
UserRoles.init()
|
||||
],
|
||||
telemetry: process.env.NODE_ENV !== 'production',
|
||||
};
|
||||
}
|
||||
|
||||
let initialized = false;
|
||||
export function ensureSuperTokensBackend() {
|
||||
if (!initialized) {
|
||||
SuperTokens.init(backendConfig());
|
||||
initialized = true;
|
||||
logger.simple("Backend initialized");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user