Add debug endpoint to verify Discord bot and web app Supabase connection
Creates a new API endpoint at `/api/discord/debug-verify` to help diagnose Supabase connection issues between the Discord bot and the web application by checking environment variables and querying verification and link data. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 5a1c39ef-e200-4d89-8fc8-f9eccc554cf6 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/saoW2ee Replit-Helium-Checkpoint-Created: true
This commit is contained in:
commit
99f465221d
1 changed files with 71 additions and 0 deletions
71
api/discord/debug-verify.ts
Normal file
71
api/discord/debug-verify.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { createClient } from "@supabase/supabase-js";
|
||||
|
||||
export const config = {
|
||||
runtime: "nodejs",
|
||||
};
|
||||
|
||||
export default async function handler(req: any, res: any) {
|
||||
const supabaseUrl = process.env.SUPABASE_URL || process.env.VITE_SUPABASE_URL;
|
||||
const supabaseServiceRole = process.env.SUPABASE_SERVICE_ROLE;
|
||||
|
||||
const debug: any = {
|
||||
timestamp: new Date().toISOString(),
|
||||
env: {
|
||||
hasSupabaseUrl: !!supabaseUrl,
|
||||
supabaseUrlPrefix: supabaseUrl?.substring(0, 30) + "...",
|
||||
hasServiceRole: !!supabaseServiceRole,
|
||||
serviceRolePrefix: supabaseServiceRole?.substring(0, 20) + "...",
|
||||
},
|
||||
};
|
||||
|
||||
if (!supabaseUrl || !supabaseServiceRole) {
|
||||
return res.status(500).json({
|
||||
error: "Missing environment variables",
|
||||
debug,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const supabase = createClient(supabaseUrl, supabaseServiceRole);
|
||||
|
||||
const { data: codes, error: codesError } = await supabase
|
||||
.from("discord_verifications")
|
||||
.select("verification_code, discord_id, expires_at, created_at")
|
||||
.order("created_at", { ascending: false })
|
||||
.limit(5);
|
||||
|
||||
debug.verificationCodes = {
|
||||
count: codes?.length || 0,
|
||||
error: codesError?.message,
|
||||
codes: codes?.map((c) => ({
|
||||
code: c.verification_code,
|
||||
discord_id: c.discord_id?.substring(0, 6) + "...",
|
||||
expires_at: c.expires_at,
|
||||
is_expired: new Date(c.expires_at) < new Date(),
|
||||
})),
|
||||
};
|
||||
|
||||
const { data: links, error: linksError } = await supabase
|
||||
.from("discord_links")
|
||||
.select("discord_id, user_id, linked_at")
|
||||
.order("linked_at", { ascending: false })
|
||||
.limit(5);
|
||||
|
||||
debug.discordLinks = {
|
||||
count: links?.length || 0,
|
||||
error: linksError?.message,
|
||||
};
|
||||
|
||||
res.status(200).json({
|
||||
status: "ok",
|
||||
message: "Supabase connection working",
|
||||
debug,
|
||||
});
|
||||
} catch (error: any) {
|
||||
res.status(500).json({
|
||||
error: "Connection failed",
|
||||
message: error?.message,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue