Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.1 kB
7
Indexable
Never
import SuperTokens from "supertokens-node";
import SessionNode from "supertokens-node/recipe/session/index.js";
import ThirdPartyPasswordlessNode from "supertokens-node/recipe/thirdpartypasswordless/index.js";
import type { TypeInput } from "supertokens-node/types";
import { appInfo } from "./appInfo";
import pkg from "supertokens-node";

const { RecipeUserId } = pkg;

export const backendConfig = (): TypeInput => {
  return {
    supertokens: {
      connectionURI: process.env.SUPERTOKENS_CONNECTION_URI || "",
      apiKey: process.env.SUPERTOKENS_API_KEY || "",
    },
    appInfo,
    recipeList: [
      ThirdPartyPasswordlessNode.init({
        override: {
          apis: (originalImplementation) => {
            return {
                ...originalImplementation,
                thirdPartySignInAndUpPOST: async function (input) {
                    input.options.res.setStatusCode(201);
                    input.options.res.sendJSONResponse({
                        message: "my custom response",
                        //...
                    })
                    return {
                        status: "OK",
                        exists: false
                    }
                }
            }
          },
        },
        providers: [
          {
            config: {
              thirdPartyId: "google",
              clients: [
                {
                  clientId:
                    "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
                  clientSecret: "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",
                  scope: ["profile", "email"]
                },
              ],
            },
          },
        ],
        contactMethod: "EMAIL_OR_PHONE",
        flowType: "USER_INPUT_CODE_AND_MAGIC_LINK",
      }),
      SessionNode.init(),
    ],
    isInServerlessEnv: true,
    framework: "custom",
  };
};

let initialized = false;
export function ensureSuperTokensInit() {
  if (!initialized) {
    SuperTokens.init(backendConfig());
    initialized = true;
  }
}
Leave a Comment