2026-03-12 19:47:28 -05:00
|
|
|
import { NextAuthOptions } from "next-auth";
|
|
|
|
|
import GoogleProvider from "next-auth/providers/google";
|
|
|
|
|
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
|
|
|
|
|
|
export const authOptions: NextAuthOptions = {
|
|
|
|
|
adapter: PrismaAdapter(prisma),
|
2026-03-12 23:20:49 -05:00
|
|
|
session: {
|
|
|
|
|
strategy: "database",
|
|
|
|
|
},
|
2026-03-12 19:47:28 -05:00
|
|
|
providers: [
|
|
|
|
|
GoogleProvider({
|
|
|
|
|
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
|
|
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
2026-03-12 23:29:00 -05:00
|
|
|
authorization: {
|
|
|
|
|
params: {
|
|
|
|
|
scope: "openid email profile https://www.googleapis.com/auth/drive.file",
|
|
|
|
|
prompt: "consent",
|
|
|
|
|
access_type: "offline",
|
|
|
|
|
response_type: "code",
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-03-12 19:47:28 -05:00
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
callbacks: {
|
2026-03-12 23:20:49 -05:00
|
|
|
async session({ session, user }) {
|
|
|
|
|
if (session?.user && user) {
|
|
|
|
|
session.user.id = user.id;
|
2026-07-01 19:43:36 -05:00
|
|
|
session.user.role = user.role || 'EMPLOYEE';
|
2026-03-12 19:47:28 -05:00
|
|
|
}
|
|
|
|
|
return session;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
events: {
|
|
|
|
|
async createUser({ user }) {
|
|
|
|
|
const userCount = await prisma.user.count();
|
|
|
|
|
if (userCount === 1) {
|
|
|
|
|
await prisma.user.update({
|
|
|
|
|
where: { id: user.id },
|
|
|
|
|
data: { role: 'ADMIN' },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|