diff --git a/server/authjs-handler.ts b/server/authjs-handler.ts index 0eece00..967a380 100644 --- a/server/authjs-handler.ts +++ b/server/authjs-handler.ts @@ -41,12 +41,6 @@ const authjsConfig = { trustHost: true, // TODO: Replace secret {@see https://authjs.dev/reference/core#secret} 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: [ // TODO: Choose and implement providers // CredentialsProvider({ diff --git a/server/trpc-handler.ts b/server/trpc-handler.ts index 276f4ab..e7c8c74 100644 --- a/server/trpc-handler.ts +++ b/server/trpc-handler.ts @@ -28,7 +28,14 @@ export const trpcHandler = ((endpoint) => (request, context, runtime) => { const jwt = await getToken({ req, 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 { ...context, diff --git a/wrangler.toml b/wrangler.toml index a0442fc..7bf6bc7 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -5,4 +5,14 @@ compatibility_flags = [ "nodejs_compat" ] [vars] MILVUS_ADDRESS = "in03-639fdba4bcde098.serverless.gcp-us-west1.cloud.zilliz.com" -MILVUS_USERNAME = "db_639fdba4bcde098" \ No newline at end of file +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" \ No newline at end of file