mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-28 07:00:37 +03:00
Initial commit - project setup
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import NextAuth, { SessionStrategy } from "next-auth";
|
||||
import GoogleProvider from "next-auth/providers/google";
|
||||
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
||||
import { db } from "@/lib/db"; // Ensure this is the correct path to your Prisma client
|
||||
|
||||
if (!db) {
|
||||
throw new Error("Prisma client is not initialized. Check your database configuration.");
|
||||
}
|
||||
|
||||
export const authOptions = {
|
||||
adapter: PrismaAdapter(db),
|
||||
providers: [
|
||||
GoogleProvider({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID!,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
||||
}),
|
||||
],
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
session: {
|
||||
strategy: "database" as SessionStrategy,
|
||||
},
|
||||
callbacks: {
|
||||
async signIn({ user, account, profile }: { user: any; account: any; profile?: any }) {
|
||||
if (!user || !account || !profile) {
|
||||
console.error("Sign-in failed: Missing user, account, or profile data.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
async session({ session, user }: { session: any; user: { id: string } }) {
|
||||
session.user.id = user.id; // Attach user ID to the session
|
||||
return session;
|
||||
},
|
||||
},
|
||||
debug: true, // Enable debug mode for detailed error messages
|
||||
};
|
||||
|
||||
const handler = NextAuth(authOptions);
|
||||
|
||||
export { handler as GET, handler as POST };
|
||||
Reference in New Issue
Block a user