Improve verification check to query auth.users and clean client logging
cgen-ecd65ebfcb754a67bd783b29a2de5882
This commit is contained in:
parent
58392aa19b
commit
3da690e527
1 changed files with 12 additions and 13 deletions
|
|
@ -116,28 +116,29 @@ export function createServer() {
|
||||||
return res.status(400).json({ error: "email is required" });
|
return res.status(400).json({ error: "email is required" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!adminSupabase?.auth?.admin) {
|
if (!adminSupabase) {
|
||||||
return res
|
return res
|
||||||
.status(500)
|
.status(500)
|
||||||
.json({ error: "Supabase admin client unavailable" });
|
.json({ error: "Supabase admin client unavailable" });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, error } = await adminSupabase.auth.admin.listUsers({
|
const targetEmail = String(email).trim().toLowerCase();
|
||||||
email,
|
|
||||||
});
|
// Query auth.users directly with the service role
|
||||||
|
const { data: user, error } = await (adminSupabase as any)
|
||||||
|
.from("auth.users")
|
||||||
|
.select("id, email, email_confirmed_at, confirmed_at")
|
||||||
|
.eq("email", targetEmail)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("[API] listUsers error:", error);
|
console.error("[API] auth.users query error:", error);
|
||||||
const errMsg =
|
|
||||||
typeof error === "string"
|
|
||||||
? error
|
|
||||||
: error?.message || JSON.stringify(error);
|
|
||||||
return res
|
return res
|
||||||
.status((error as any)?.status ?? 500)
|
.status((error as any)?.status ?? 500)
|
||||||
.json({ error: errMsg });
|
.json({ error: (error as any)?.message || "Query failed" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = (data as any)?.users?.[0] ?? null;
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return res.status(404).json({ error: "User not found" });
|
return res.status(404).json({ error: "User not found" });
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +147,6 @@ export function createServer() {
|
||||||
|
|
||||||
if (verified) {
|
if (verified) {
|
||||||
try {
|
try {
|
||||||
// Look up the Founding Member achievement
|
|
||||||
const { data: ach, error: aErr } = await adminSupabase
|
const { data: ach, error: aErr } = await adminSupabase
|
||||||
.from("achievements")
|
.from("achievements")
|
||||||
.select("id")
|
.select("id")
|
||||||
|
|
@ -154,7 +154,6 @@ export function createServer() {
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
|
|
||||||
if (!aErr && ach?.id) {
|
if (!aErr && ach?.id) {
|
||||||
// Award it if not already awarded
|
|
||||||
const { error: uaErr } = await adminSupabase
|
const { error: uaErr } = await adminSupabase
|
||||||
.from("user_achievements")
|
.from("user_achievements")
|
||||||
.upsert(
|
.upsert(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue