mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-29 13:00:58 +03:00
Youtube Handle, working
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import NextAuth, { SessionStrategy } from "next-auth";
|
import NextAuth, { SessionStrategy } from "next-auth";
|
||||||
import GoogleProvider from "next-auth/providers/google";
|
import GoogleProvider from "next-auth/providers/google";
|
||||||
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
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";
|
import axios from "axios";
|
||||||
|
|
||||||
if (!db) {
|
if (!db) {
|
||||||
@@ -34,7 +34,8 @@ export const authOptions = {
|
|||||||
|
|
||||||
if (account.provider === "google" && account.access_token) {
|
if (account.provider === "google" && account.access_token) {
|
||||||
try {
|
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: {
|
params: {
|
||||||
part: "brandingSettings",
|
part: "brandingSettings",
|
||||||
mine: "true",
|
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 customUrl = data.items?.[0]?.snippet?.customUrl;
|
||||||
const youtubeHandle = customUrl ? `@${customUrl.replace(/^.*\//, "")}` : null;
|
|
||||||
|
const youtubeHandle = customUrl ;
|
||||||
|
|
||||||
console.log("Fetched YouTube handle:", youtubeHandle);
|
console.log("Fetched YouTube handle:", youtubeHandle);
|
||||||
|
|
||||||
// Attach ONLY the handle to the user
|
|
||||||
user.youtubeHandle = youtubeHandle;
|
user.youtubeHandle = youtubeHandle;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user