Without domain: .vibnai.com the cookie is scoped to vibnai.com only. Browsers don't send it to theia.vibnai.com, so ForwardAuth sees no token and redirects to login even when the user is already logged in. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { NextAuthOptions } from "next-auth";
|
|
import GoogleProvider from "next-auth/providers/google";
|
|
import { PrismaAdapter } from "@auth/prisma-adapter";
|
|
import { PrismaClient } from "@prisma/client";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
export const authOptions: NextAuthOptions = {
|
|
adapter: PrismaAdapter(prisma),
|
|
providers: [
|
|
GoogleProvider({
|
|
clientId: process.env.GOOGLE_CLIENT_ID || "",
|
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
|
|
}),
|
|
],
|
|
pages: {
|
|
signIn: "/auth",
|
|
error: "/auth",
|
|
},
|
|
callbacks: {
|
|
async session({ session, user }) {
|
|
if (session.user) {
|
|
session.user.id = user.id;
|
|
}
|
|
return session;
|
|
},
|
|
},
|
|
session: {
|
|
strategy: "database",
|
|
maxAge: 30 * 24 * 60 * 60, // 30 days
|
|
},
|
|
secret: process.env.NEXTAUTH_SECRET,
|
|
cookies: {
|
|
sessionToken: {
|
|
name: `__Secure-next-auth.session-token`,
|
|
options: {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
path: "/",
|
|
secure: true,
|
|
domain: ".vibnai.com", // share across all subdomains (theia.vibnai.com, etc.)
|
|
},
|
|
},
|
|
},
|
|
};
|