mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-22 09:00:58 +03:00
Youtube handle try, not working, user input for it.
This commit is contained in:
@@ -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;
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user