fix: authjs reads correct cookie in dev and prod

master
Avraham Sakal 3 weeks ago
parent 67841355ac
commit 83254fb770

@ -41,12 +41,6 @@ const authjsConfig = {
trustHost: true, trustHost: true,
// TODO: Replace secret {@see https://authjs.dev/reference/core#secret} // TODO: Replace secret {@see https://authjs.dev/reference/core#secret}
secret: "buginoo", secret: "buginoo",
/** Needed to specify cookie name because for some reason in production it
* wasn't reading the correct cookie but in development it was. So we need to
* make sure both development and production are using the same cookie name.*/
cookies: {
state: { name: "__Secure-authjs.session-token" },
},
providers: [ providers: [
// TODO: Choose and implement providers // TODO: Choose and implement providers
// CredentialsProvider({ // CredentialsProvider({

@ -28,7 +28,14 @@ export const trpcHandler = ((endpoint) => (request, context, runtime) => {
const jwt = await getToken({ const jwt = await getToken({
req, req,
secret: "buginoo", secret: "buginoo",
cookieName: "__Secure-authjs.session-token", /** Needed to specify cookie name because for some reason in production
* it wasn't reading the correct cookie but in development it was. It
* was not straightforward to fix the name of the cookie in
* `authOptions`, so I adjusted what cookie to read from here: */
cookieName:
env.NODE_ENV === "production"
? "__Secure-authjs.session-token"
: "authjs.session-token",
}); });
return { return {
...context, ...context,

@ -6,3 +6,13 @@ compatibility_flags = [ "nodejs_compat" ]
[vars] [vars]
MILVUS_ADDRESS = "in03-639fdba4bcde098.serverless.gcp-us-west1.cloud.zilliz.com" MILVUS_ADDRESS = "in03-639fdba4bcde098.serverless.gcp-us-west1.cloud.zilliz.com"
MILVUS_USERNAME = "db_639fdba4bcde098" MILVUS_USERNAME = "db_639fdba4bcde098"
[env.production.vars]
MILVUS_ADDRESS = "in03-639fdba4bcde098.serverless.gcp-us-west1.cloud.zilliz.com"
MILVUS_USERNAME = "db_639fdba4bcde098"
NODE_ENV = "production"
[env.preview.vars]
MILVUS_ADDRESS = "in03-639fdba4bcde098.serverless.gcp-us-west1.cloud.zilliz.com"
MILVUS_USERNAME = "db_639fdba4bcde098"
NODE_ENV = "development"
Loading…
Cancel
Save