diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index b7a25f6..7386ab3 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,7 +1,7 @@ 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 { db } from "@/lib/db"; import axios from "axios"; if (!db) { @@ -34,7 +34,8 @@ export const authOptions = { if (account.provider === "google" && account.access_token) { try { - const { data } = await axios.get("https://www.googleapis.com/youtube/v3/channels", { + 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", @@ -44,14 +45,13 @@ export const authOptions = { }, }); - const customUrl = data.items?.[0]?.brandingSettings?.channel?.customUrl; + console.log("YouTube API response:", JSON.stringify(data)); - // Create the handle - const youtubeHandle = customUrl ? `@${customUrl.replace(/^.*\//, "")}` : null; + const customUrl = data.items?.[0]?.snippet?.customUrl; + + const youtubeHandle = customUrl ; console.log("Fetched YouTube handle:", youtubeHandle); - - // Attach ONLY the handle to the user user.youtubeHandle = youtubeHandle; } catch (error) {