mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-29 15:00:59 +03:00
fix build
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { getServerSession } from "next-auth";
|
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 { redirect } from "next/navigation";
|
||||||
import AdminClient from "./AdminClient"; // Adjust the import path as necessary
|
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
|
||||||
|
};
|
||||||
@@ -1,78 +1,11 @@
|
|||||||
import NextAuth, { SessionStrategy } from "next-auth";
|
import NextAuth from "next-auth";
|
||||||
import GoogleProvider from "next-auth/providers/google";
|
|
||||||
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import axios from "axios";
|
import { authOptions } from "./authOptions";
|
||||||
|
|
||||||
if (!db) {
|
if (!db) {
|
||||||
throw new Error("Prisma client is not initialized. Check your database configuration.");
|
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);
|
const handler = NextAuth(authOptions);
|
||||||
|
|
||||||
export { handler as GET, handler as POST };
|
export { handler as GET, handler as POST };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getServerSession } from "next-auth";
|
import { getServerSession } from "next-auth";
|
||||||
import { authOptions } from "../auth/[...nextauth]/route";
|
import { authOptions } from "../auth/[...nextauth]/authOptions";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getServerSession } from "next-auth";
|
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 { db } from "@/lib/db";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import GiveawayCard from "@/components/GiveawayCard";
|
import GiveawayCard from "@/components/GiveawayCard";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getServerSession } from "next-auth";
|
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 { db } from "@/lib/db";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import ProfileClient from "./ProfileClient";
|
import ProfileClient from "./ProfileClient";
|
||||||
|
|||||||
Reference in New Issue
Block a user