chunkygoo.
12/16/2022, 7:31 AMrp_st
12/16/2022, 7:32 AMrp_st
12/16/2022, 7:33 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");
}
}
chunkygoo.
12/16/2022, 7:33 AMchunkygoo.
12/16/2022, 7:34 AMchunkygoo.
12/16/2022, 7:34 AMif (typeof window !== "undefined") {
// we only want to call this init function on the frontend, so we check typeof window !== 'undefined'
SuperTokensReact.init(frontendConfig);
}
rp_st
12/16/2022, 8:14 AMrp_st
12/16/2022, 8:15 AMchunkygoo.
12/16/2022, 8:04 PMchunkygoo.
12/16/2022, 8:04 PMrp_st
12/17/2022, 4:06 AMrp_st
12/17/2022, 4:06 AMchunkygoo.
12/18/2022, 6:16 AMchunkygoo.
12/18/2022, 6:16 AMchunkygoo.
12/18/2022, 6:17 AMchunkygoo.
12/18/2022, 6:17 AMrp_st
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?nkshah2
12/19/2022, 5:13 AMnkshah2
12/19/2022, 5:13 AMSuperTokensReact.init
then I would double check if that is being executed multiple timeschunkygoo.
12/19/2022, 5:15 AMchunkygoo.
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);
}
chunkygoo.
12/19/2022, 5:16 AMchunkygoo.
12/19/2022, 5:16 AMnkshah2
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 PMchunkygoo.
12/19/2022, 10:47 PMnkshah2
12/20/2022, 4:21 AMSuperTokensReact.init(frontendConfig());
chunkygoo.
12/21/2022, 5:08 AMchunkygoo.
12/21/2022, 5:08 AMchunkygoo.
12/21/2022, 5:08 AMnkshah2
12/21/2022, 5:09 AMchunkygoo.
12/21/2022, 5:10 AMnkshah2
12/21/2022, 5:13 AMnkshah2
12/21/2022, 5:14 AMchunkygoo.
12/21/2022, 5:21 AMchunkygoo.
12/21/2022, 5:22 AMchunkygoo.
12/21/2022, 5:22 AMchunkygoo.
12/21/2022, 5:22 AMchunkygoo.
12/21/2022, 5:22 AMnkshah2
12/21/2022, 5:23 AMchunkygoo.
12/21/2022, 5:23 AMchunkygoo.
12/21/2022, 5:23 AMchunkygoo.
12/21/2022, 5:23 AMchunkygoo.
12/21/2022, 5:23 AMchunkygoo.
12/21/2022, 5:23 AMchunkygoo.
12/21/2022, 5:23 AMnkshah2
12/21/2022, 5:23 AMnkshah2
12/21/2022, 5:24 AMchunkygoo.
12/21/2022, 5:24 AMchunkygoo.
12/21/2022, 5:24 AMnkshah2
12/21/2022, 5:24 AMchunkygoo.
12/21/2022, 5:24 AMchunkygoo.
12/21/2022, 5:29 AMchunkygoo.
12/21/2022, 5:29 AMchunkygoo.
12/21/2022, 5:30 AMchunkygoo.
12/21/2022, 5:31 AMnkshah2
12/21/2022, 5:31 AMchunkygoo.
12/21/2022, 5:31 AMchunkygoo.
12/21/2022, 5:31 AMnkshah2
12/21/2022, 5:31 AMchunkygoo.
12/21/2022, 5:32 AMchunkygoo.
12/21/2022, 5:32 AMnkshah2
12/21/2022, 5:32 AMnkshah2
12/21/2022, 5:32 AMchunkygoo.
12/21/2022, 5:32 AMchunkygoo.
12/21/2022, 5:32 AMchunkygoo.
12/21/2022, 5:33 AMchunkygoo.
12/21/2022, 5:33 AMnkshah2
12/21/2022, 5:33 AMnkshah2
12/21/2022, 5:33 AMchunkygoo.
12/21/2022, 5:33 AM