Youtube Handle, working

This commit is contained in:
EdiFarcas
2025-04-29 12:57:41 +03:00
parent f0a77b1c9c
commit 7fd2080d58
+7 -7
View File
@@ -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) {