Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Session = require("supertokens-node/recipe/session")
- const ThirdPartyEmailPassword = require("supertokens-node/recipe/thirdpartyemailpassword")
- const express = require("express")
- const cors = require("cors")
- const supertokens = require("supertokens-node")
- const { errorHandler, middleware } = require("supertokens-node/framework/express")
- const Dashboard = require("supertokens-node/recipe/dashboard")
- let { Google, Github, Apple } = ThirdPartyEmailPassword;
- supertokens.init({
- framework: "express",
- supertokens: {
- // https://try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
- // connectionURI: "https://try.supertokens.com",
- connectionURI: "http://localhost:3567",
- // apiKey: '5b2bc6ac-170f-4c16-90f6-81831e46b01e',
- },
- appInfo: {
- // learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo
- appName: "shaggaga-buyer",
- apiDomain: "https://api-https-domain",
- websiteDomain: "https://frontend-domain",
- apiBasePath: "/",
- websiteBasePath: "/auth"
- },
- recipeList: [
- ThirdPartyEmailPassword.init({
- providers: [
- // We have provided you with development keys which you can use for testing.
- // IMPORTANT: Please replace them with your own OAuth keys for production use.
- Google({
- clientId: "$$ClientId",
- clientSecret : "$$clientSecret"
- }),
- ]
- }),
- Session.init({
- jwt: {
- enable: true,
- },
- override: {
- functions: function (originalImplementation) {
- return {
- ...originalImplementation,
- createNewSession: async function (input) {
- input.accessTokenPayload = {
- ...input.accessTokenPayload,
- "https://hasura.io/jwt/claims": {
- "x-hasura-user-id": input.userId,
- "x-hasura-default-role": "user",
- "x-hasura-allowed-roles": ["user"],
- }
- };
- return originalImplementation.createNewSession(input);
- },
- };
- }
- },
- }), // initializes session features
- Dashboard.init({
- apiKey: "$$apiKey"
- }),
- ]
- });
- let app = express();
- app.use(cors({
- origin: "https://frontend-domain",
- allowedHeaders: ["content-type", 'rid', 'fdi-version', 'anti-csrf', 'authorization', 'st-auth-mode'],
- methods: ["GET", "PUT", "POST", "DELETE"],
- credentials: true,
- }));
- app.use(middleware());
- app.listen(10123, () => {
- console.log("Listening on port 10123");
- });
Advertisement
Add Comment
Please, Sign In to add comment