mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-22 09:00:58 +03:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
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
|
|
import axios from "axios";
|
|
|
|
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!,
|
|
authorization: {
|
|
params: {
|
|
scope: "openid email profile https://www.googleapis.com/auth/youtube.readonly",
|
|
},
|
|
},
|
|
}),
|
|
],
|
|
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 };
|