Youtube handle try, not working, user input for it.

This commit is contained in:
EdiFarcas
2025-04-28 15:26:52 +03:00
parent 7f744e1e9f
commit 7c4707d677
6 changed files with 158 additions and 18 deletions
+31 -2
View File
@@ -31,10 +31,39 @@ export const authOptions = {
console.error("Sign-in failed: Missing user, account, or profile data.");
return false;
}
if (account.provider === "google" && account.access_token) {
try {
const { data } = await axios.get("https://www.googleapis.com/youtube/v3/channels", {
params: {
part: "brandingSettings",
mine: "true",
},
headers: {
Authorization: `Bearer ${account.access_token}`,
},
});
const customUrl = data.items?.[0]?.brandingSettings?.channel?.customUrl;
// Create the handle
const youtubeHandle = customUrl ? `@${customUrl.replace(/^.*\//, "")}` : null;
console.log("Fetched YouTube handle:", youtubeHandle);
// Attach ONLY the handle to the user
user.youtubeHandle = youtubeHandle;
} catch (error) {
console.error("Error fetching YouTube handle:", error);
}
}
return true;
},
async session({ session, user }: { session: any; user: { id: string } }) {
session.user.id = user.id; // Attach user ID to the session
async session({ session, user }: { session: any; user: any }) {
session.user.id = user.id;
session.user.youtubeHandle = user.youtubeHandle; // Only attach YouTube handle
return session;
},
},