Chunkygoo
12/16/2022, 7:31 AMrp
12/16/2022, 7:32 AMChunkygoo
12/16/2022, 7:33 AMimport type { Request, Response } from "express";
import type { NextApiRequest, NextApiResponse } from "next";
import NextCors from "nextjs-cors";
import supertokens from "supertokens-node";
import { middleware } from "supertokens-node/framework/express";
import { superTokensNextWrapper } from "supertokens-node/nextjs";
import { backendConfig } from "../../../config/backendConfig";
import { env } from "../../../env/server.mjs";
supertokens.init(backendConfig());
export default async function superTokens(
req: NextApiRequest & Request,
res: NextApiResponse & Response
) {
// 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: env.APP_URL,
credentials: true,
allowedHeaders: ["content-type", ...supertokens.getAllCORSHeaders()],
});
await superTokensNextWrapper(
async (next) => {
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");
}
}
if (typeof window !== "undefined") {
// we only want to call this init function on the frontend, so we check typeof window !== 'undefined'
SuperTokensReact.init(frontendConfig);
}
rp
12/16/2022, 8:14 AMChunkygoo
12/16/2022, 8:04 PMrp
12/17/2022, 4:06 AMChunkygoo
12/18/2022, 6:16 AMrp
12/18/2022, 11:17 AMChunkygoo
12/18/2022, 7:06 PMnkshah2
12/19/2022, 5:12 AMnpx create-supertokens-app@latest
and choose NextJS to see if this issue can be replicated there?SuperTokensReact.init
then I would double check if that is being executed multiple timesChunkygoo
12/19/2022, 5:15 AMif (typeof window !== "undefined") {
// we only want to call this init function on the frontend, so we check typeof window !== 'undefined'
SuperTokensReact.init(frontendConfig);
}
nkshah2
12/19/2022, 5:18 AMuseEffect
by default runs on client side so you could use that. As a side note, the log isnt an error and wont cause any side effectsChunkygoo
12/19/2022, 10:30 PMnkshah2
12/20/2022, 4:21 AMSuperTokensReact.init(frontendConfig());
Chunkygoo
12/21/2022, 5:08 AMnkshah2
12/21/2022, 5:09 AMChunkygoo
12/21/2022, 5:10 AMnkshah2
12/21/2022, 5:13 AMChunkygoo
12/21/2022, 5:21 AMnkshah2
12/21/2022, 5:23 AMChunkygoo
12/21/2022, 5:23 AMnkshah2
12/21/2022, 5:23 AMChunkygoo
12/21/2022, 5:24 AMnkshah2
12/21/2022, 5:24 AMChunkygoo
12/21/2022, 5:24 AMnkshah2
12/21/2022, 5:31 AMChunkygoo
12/21/2022, 5:31 AMnkshah2
12/21/2022, 5:31 AMChunkygoo
12/21/2022, 5:32 AMnkshah2
12/21/2022, 5:32 AMChunkygoo
12/21/2022, 5:32 AMnkshah2
12/21/2022, 5:33 AMChunkygoo
12/21/2022, 5:33 AM