fix build

This commit is contained in:
Alexandru Eduard Farcas
2025-05-18 10:24:54 +03:00
parent f8144fb5ac
commit 613957c5eb
6 changed files with 76 additions and 73 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
import { getServerSession } from "next-auth";
import { authOptions } from "../api/auth/[...nextauth]/route";
import { authOptions } from "../api/auth/[...nextauth]/authOptions";
import { redirect } from "next/navigation";
import AdminClient from "./AdminClient"; // Adjust the import path as necessary
@@ -0,0 +1,70 @@
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import GoogleProvider from "next-auth/providers/google";
import { SessionStrategy } from "next-auth";
import { db } from "@/lib/db";
import axios from "axios";
export const authOptions = {
adapter: PrismaAdapter(db),
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
allowDangerousEmailAccountLinking: true,
authorization: {
params: {
scope: "openid email profile https://www.googleapis.com/auth/youtube.readonly",
},
},
}),
],
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: "database" as SessionStrategy,
},
callbacks: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
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;
}
if (account.provider === "google" && account.access_token) {
try {
console.log("Fetching YouTube handle for user:", user.email);
const { data } = await axios.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true", {
params: {
part: "brandingSettings",
mine: "true",
},
headers: {
Authorization: `Bearer ${account.access_token}`,
},
});
console.log("YouTube API response:", JSON.stringify(data));
const customUrl = data.items?.[0]?.snippet?.customUrl;
const youtubeHandle = customUrl ;
console.log("Fetched YouTube handle:", youtubeHandle);
user.youtubeHandle = youtubeHandle;
} catch (error) {
console.error("Error fetching YouTube handle:", error);
}
}
return true;
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async session({ session, user }: { session: any; user: any }) {
session.user.id = user.id;
session.user.youtubeHandle = user.youtubeHandle; // Only attach YouTube handle
return session;
},
},
debug: true, // Enable debug mode for detailed error messages
};
+2 -69
View File
@@ -1,78 +1,11 @@
import NextAuth, { SessionStrategy } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import NextAuth from "next-auth";
import { db } from "@/lib/db";
import axios from "axios";
import { authOptions } from "./authOptions";
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!,
allowDangerousEmailAccountLinking: true,
authorization: {
params: {
scope: "openid email profile https://www.googleapis.com/auth/youtube.readonly",
},
},
}),
],
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: "database" as SessionStrategy,
},
callbacks: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
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;
}
if (account.provider === "google" && account.access_token) {
try {
console.log("Fetching YouTube handle for user:", user.email);
const { data } = await axios.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true", {
params: {
part: "brandingSettings",
mine: "true",
},
headers: {
Authorization: `Bearer ${account.access_token}`,
},
});
console.log("YouTube API response:", JSON.stringify(data));
const customUrl = data.items?.[0]?.snippet?.customUrl;
const youtubeHandle = customUrl ;
console.log("Fetched YouTube handle:", youtubeHandle);
user.youtubeHandle = youtubeHandle;
} catch (error) {
console.error("Error fetching YouTube handle:", error);
}
}
return true;
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async session({ session, user }: { session: any; user: any }) {
session.user.id = user.id;
session.user.youtubeHandle = user.youtubeHandle; // Only attach YouTube handle
return session;
},
},
debug: true, // Enable debug mode for detailed error messages
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
+1 -1
View File
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "../auth/[...nextauth]/route";
import { authOptions } from "../auth/[...nextauth]/authOptions";
import { db } from "@/lib/db";
export async function POST(req: Request) {
+1 -1
View File
@@ -1,5 +1,5 @@
import { getServerSession } from "next-auth";
import { authOptions } from "../api/auth/[...nextauth]/route";
import { authOptions } from "../api/auth/[...nextauth]/authOptions";
import { db } from "@/lib/db";
import { redirect } from "next/navigation";
import GiveawayCard from "@/components/GiveawayCard";
+1 -1
View File
@@ -1,5 +1,5 @@
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions";
import { db } from "@/lib/db";
import { redirect } from "next/navigation";
import ProfileClient from "./ProfileClient";