Prettier format pending files

This commit is contained in:
Builder.io 2025-11-09 23:43:44 +00:00
parent 39aa2d8c2a
commit 890744574b
3 changed files with 57 additions and 29 deletions

View file

@ -1,6 +1,7 @@
import { createClient } from "@supabase/supabase-js";
const supabaseUrl = process.env.VITE_SUPABASE_URL || "https://kmdeisowhtsalsekkzqd.supabase.co";
const supabaseUrl =
process.env.VITE_SUPABASE_URL || "https://kmdeisowhtsalsekkzqd.supabase.co";
const supabaseServiceRole = process.env.SUPABASE_SERVICE_ROLE || "";
export default async function handler(req: any, res: any) {
@ -25,19 +26,22 @@ export default async function handler(req: any, res: any) {
}
// Exchange authorization code for access token
const tokenResponse = await fetch("https://discord.com/api/v10/oauth2/token", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
const tokenResponse = await fetch(
"https://discord.com/api/v10/oauth2/token",
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
grant_type: "authorization_code",
code,
redirect_uri: "https://127.0.0.1", // Placeholder for Activity
}).toString(),
},
body: new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
grant_type: "authorization_code",
code,
redirect_uri: "https://127.0.0.1", // Placeholder for Activity
}).toString(),
});
);
if (!tokenResponse.ok) {
const error = await tokenResponse.json();
@ -69,7 +73,10 @@ export default async function handler(req: any, res: any) {
}
const discordUser = await userResponse.json();
console.log("[Discord Token] Token exchange successful for user:", discordUser.id);
console.log(
"[Discord Token] Token exchange successful for user:",
discordUser.id,
);
// Return access token to Activity
return res.status(200).json({

View file

@ -116,7 +116,9 @@ export const DiscordActivityProvider: React.FC<
prompt: "none",
});
console.log("[Discord Activity] Got authorization code, exchanging for token...");
console.log(
"[Discord Activity] Got authorization code, exchanging for token...",
);
// Exchange code for access token via our backend
const tokenResponse = await fetch("/api/discord/token", {
@ -130,7 +132,10 @@ export const DiscordActivityProvider: React.FC<
if (!tokenResponse.ok) {
const errorData = await tokenResponse.json();
const errMsg = errorData.error || "Failed to exchange code";
console.error("[Discord Activity] Token exchange failed:", errMsg);
console.error(
"[Discord Activity] Token exchange failed:",
errMsg,
);
setError(errMsg);
setIsLoading(false);
return;
@ -139,7 +144,9 @@ export const DiscordActivityProvider: React.FC<
const tokenData = await tokenResponse.json();
const access_token = tokenData.access_token;
console.log("[Discord Activity] Got access token, authenticating with SDK...");
console.log(
"[Discord Activity] Got access token, authenticating with SDK...",
);
// Authenticate with SDK using the access token
const authResult = await sdk.commands.authenticate({
@ -153,15 +160,20 @@ export const DiscordActivityProvider: React.FC<
return;
}
console.log("[Discord Activity] Authenticated with SDK, fetching user profile...");
console.log(
"[Discord Activity] Authenticated with SDK, fetching user profile...",
);
setAuth(authResult);
// Get user info using the access token
const userResponse = await fetch("https://discord.com/api/v10/users/@me", {
headers: {
Authorization: `Bearer ${access_token}`,
const userResponse = await fetch(
"https://discord.com/api/v10/users/@me",
{
headers: {
Authorization: `Bearer ${access_token}`,
},
},
});
);
if (!userResponse.ok) {
console.error("[Discord Activity] Failed to fetch user profile");
@ -171,13 +183,17 @@ export const DiscordActivityProvider: React.FC<
}
const discordUserData = await userResponse.json();
console.log("[Discord Activity] User profile fetched:", discordUserData.username);
console.log(
"[Discord Activity] User profile fetched:",
discordUserData.username,
);
// Store the user data
const userData: DiscordUser = {
id: discordUserData.id,
discord_id: discordUserData.id,
full_name: discordUserData.global_name || discordUserData.username,
full_name:
discordUserData.global_name || discordUserData.username,
username: discordUserData.username,
avatar_url: discordUserData.avatar
? `https://cdn.discordapp.com/avatars/${discordUserData.id}/${discordUserData.avatar}.png`

View file

@ -943,15 +943,20 @@ export function createServer() {
if (!accessToken) {
console.error("[Discord Token] No access token in response");
return res.status(500).json({ error: "Failed to obtain access token" });
return res
.status(500)
.json({ error: "Failed to obtain access token" });
}
// Fetch Discord user info to ensure token is valid
const userResponse = await fetch("https://discord.com/api/v10/users/@me", {
headers: {
Authorization: `Bearer ${accessToken}`,
const userResponse = await fetch(
"https://discord.com/api/v10/users/@me",
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
});
);
if (!userResponse.ok) {
console.error("[Discord Token] Failed to fetch user info");