mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-22 07:00:57 +03:00
Youtube Handle, working
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user