Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Fix cookies (#378)

Sean Boult8a13c5c76491
diff --git a/packages/auth/src/server.ts b/packages/auth/src/server.ts
index 753d3504..eb982f35 100644
--- a/packages/auth/src/server.ts
+++ b/packages/auth/src/server.ts
@@ -101,7 +101,9 @@ export const authOptions: NextAuthOptions = {
}),
],
};
+
const useSecureCookies = Boolean(process.env.VERCEL_URL);
+const appHostname = new URL(process.env.VERCEL_URL ?? 'http://127.0.0.1').hostname;
export const adminAuthOptions: NextAuthOptions = {
...authOptions,
@@ -112,12 +114,13 @@ export const adminAuthOptions: NextAuthOptions = {
httpOnly: true,
sameSite: 'lax',
path: '/',
- domain: `${process.env.VERCEL_URL}`,
+ domain: appHostname,
secure: useSecureCookies,
},
},
},
};
+
/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*