fatih.55
10/09/2023, 10:52 AMInitialisation not done. Did you forget to call the UserRoles.init or SuperTokens.init functions?
when I try to create a role. Does anyone have an idea what I could be doing wrong?nkshah2
10/09/2023, 10:52 AMnkshah2
10/09/2023, 10:52 AMnkshah2
10/09/2023, 10:52 AMfatih.55
10/09/2023, 10:53 AMnkshah2
10/09/2023, 10:53 AMfatih.55
10/09/2023, 10:53 AMnkshah2
10/09/2023, 10:53 AMfatih.55
10/09/2023, 10:54 AM/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import EmailPasswordNode from "supertokens-node/recipe/emailpassword";
import SessionNode from "supertokens-node/recipe/session";
import { appInfo } from "./appInfo";
import type { TypeInput } from "supertokens-node/types";
import Dashboard from "supertokens-node/recipe/dashboard";
import UserRoles from "supertokens-node/recipe/userroles";
import { env } from "~/env.mjs";
export const backendConfig = (): TypeInput => {
return {
framework: "express",
supertokens: {
// These are the connection details of the app you created on supertokens.com
connectionURI: env.SUPERTOKENS_CONNECTION_URI,
apiKey: env.SUPERTOKENS_API_KEY,
},
appInfo,
recipeList: [
EmailPasswordNode.init(),
SessionNode.init(),
UserRoles.init(),
Dashboard.init(),
],
isInServerlessEnv: true,
};
};
nkshah2
10/09/2023, 10:54 AMfatih.55
10/09/2023, 10:55 AMnkshah2
10/09/2023, 10:55 AMnkshah2
10/09/2023, 10:56 AMfatih.55
10/09/2023, 10:56 AMnkshah2
10/09/2023, 10:56 AMfatih.55
10/09/2023, 10:56 AMimport { superTokensNextWrapper } from "supertokens-node/nextjs";
import { middleware } from "supertokens-node/framework/express";
import type { NextApiRequest, NextApiResponse } from "next";
import supertokens from "supertokens-node";
import { backendConfig } from "~/config/backendConfig";
import NextCors from "nextjs-cors";
const getBaseUrl = () => {
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost
};
supertokens.init(backendConfig());
export default async function superTokens(
req: NextApiRequest,
res: NextApiResponse,
) {
// NOTE: We need CORS only if we are querying the APIs from a different origin
await NextCors(req, res, {
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
origin: getBaseUrl(),
credentials: true,
allowedHeaders: ["content-type", ...supertokens.getAllCORSHeaders()],
});
await superTokensNextWrapper(
async (next) => {
// This is needed for production deployments with Vercel
res.setHeader(
"Cache-Control",
"no-cache, no-store, max-age=0, must-revalidate",
);
await middleware()(req, res, next);
},
req,
res,
);
if (!res.writableEnded) {
res.status(404).send("Not found");
}
}
fatih.55
10/09/2023, 10:57 AMnkshah2
10/09/2023, 10:57 AMnkshah2
10/09/2023, 10:57 AMsupertokens.init(backendConfig());
fatih.55
10/09/2023, 10:58 AMsupertokens.init(backendConfig());
in there?nkshah2
10/09/2023, 10:59 AMfatih.55
10/09/2023, 10:59 AMnkshah2
10/09/2023, 10:59 AM