fix: authjs reads correct cookie in dev and prod

This commit is contained in:
Avraham Sakal
2025-09-21 20:41:44 -04:00
parent 67841355ac
commit 83254fb770
3 changed files with 19 additions and 8 deletions
-6
View File
@@ -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({
+8 -1
View File
@@ -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,