Prettier format pending files
This commit is contained in:
parent
6bff1bdd10
commit
7b6082adf7
5 changed files with 63 additions and 21 deletions
|
|
@ -219,7 +219,7 @@ export const storage = supabase.storage;
|
||||||
export const channel = supabase.channel;
|
export const channel = supabase.channel;
|
||||||
|
|
||||||
// Test function for debugging
|
// Test function for debugging
|
||||||
;(window as any).testSupabase = async () => {
|
(window as any).testSupabase = async () => {
|
||||||
console.log("🧪 Manual Supabase Test");
|
console.log("🧪 Manual Supabase Test");
|
||||||
console.log("URL:", supabaseUrl);
|
console.log("URL:", supabaseUrl);
|
||||||
console.log("Key configured:", !!supabaseAnonKey);
|
console.log("Key configured:", !!supabaseAnonKey);
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,13 @@ import {
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { user, profile, loading: authLoading, updateProfile, profileComplete } = useAuth();
|
const {
|
||||||
|
user,
|
||||||
|
profile,
|
||||||
|
loading: authLoading,
|
||||||
|
updateProfile,
|
||||||
|
profileComplete,
|
||||||
|
} = useAuth();
|
||||||
const [displayName, setDisplayName] = useState("");
|
const [displayName, setDisplayName] = useState("");
|
||||||
const [locationInput, setLocationInput] = useState("");
|
const [locationInput, setLocationInput] = useState("");
|
||||||
const [bio, setBio] = useState("");
|
const [bio, setBio] = useState("");
|
||||||
|
|
@ -491,7 +497,9 @@ export default function Dashboard() {
|
||||||
Level {profile?.level || 1}
|
Level {profile?.level || 1}
|
||||||
</Badge>
|
</Badge>
|
||||||
{profileComplete && (
|
{profileComplete && (
|
||||||
<Badge className="mt-2 ml-2 bg-green-600 text-white border-green-500">Profile Complete</Badge>
|
<Badge className="mt-2 ml-2 bg-green-600 text-white border-green-500">
|
||||||
|
Profile Complete
|
||||||
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,11 @@ export default function Onboarding() {
|
||||||
if (!ensureResp.ok) {
|
if (!ensureResp.ok) {
|
||||||
const text = await ensureResp.text().catch(() => "");
|
const text = await ensureResp.text().catch(() => "");
|
||||||
let parsedError: any = undefined;
|
let parsedError: any = undefined;
|
||||||
try { parsedError = JSON.parse(text); } catch {}
|
try {
|
||||||
const message = parsedError?.error || text || `HTTP ${ensureResp.status}`;
|
parsedError = JSON.parse(text);
|
||||||
|
} catch {}
|
||||||
|
const message =
|
||||||
|
parsedError?.error || text || `HTTP ${ensureResp.status}`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,16 @@ export function createServer() {
|
||||||
try {
|
try {
|
||||||
app.get("/api/health", async (_req, res) => {
|
app.get("/api/health", async (_req, res) => {
|
||||||
try {
|
try {
|
||||||
const { error } = await adminSupabase.from("user_profiles").select("count", { count: "exact", head: true });
|
const { error } = await adminSupabase
|
||||||
if (error) return res.status(500).json({ ok: false, error: error.message });
|
.from("user_profiles")
|
||||||
|
.select("count", { count: "exact", head: true });
|
||||||
|
if (error)
|
||||||
|
return res.status(500).json({ ok: false, error: error.message });
|
||||||
return res.json({ ok: true });
|
return res.json({ ok: true });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return res.status(500).json({ ok: false, error: e?.message || String(e) });
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json({ ok: false, error: e?.message || String(e) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -121,18 +126,29 @@ export function createServer() {
|
||||||
const code: string = (error as any).code || "";
|
const code: string = (error as any).code || "";
|
||||||
|
|
||||||
// Handle duplicate username
|
// Handle duplicate username
|
||||||
if (code === "23505" || message.includes("duplicate key") || message.includes("username")) {
|
if (
|
||||||
|
code === "23505" ||
|
||||||
|
message.includes("duplicate key") ||
|
||||||
|
message.includes("username")
|
||||||
|
) {
|
||||||
const suffix = Math.random().toString(36).slice(2, 6);
|
const suffix = Math.random().toString(36).slice(2, 6);
|
||||||
const newUsername = `${String(username || "user").slice(0, 20)}_${suffix}`;
|
const newUsername = `${String(username || "user").slice(0, 20)}_${suffix}`;
|
||||||
console.log("[API] retrying with unique username", newUsername);
|
console.log("[API] retrying with unique username", newUsername);
|
||||||
attempt = await tryUpsert({ id, ...profile, username: newUsername });
|
attempt = await tryUpsert({
|
||||||
|
id,
|
||||||
|
...profile,
|
||||||
|
username: newUsername,
|
||||||
|
});
|
||||||
error = normalizeError(attempt.error);
|
error = normalizeError(attempt.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
// Possible foreign key violation: auth.users missing
|
// Possible foreign key violation: auth.users missing
|
||||||
if ((error as any).code === "23503" || (error as any).message?.includes("foreign key")) {
|
if (
|
||||||
|
(error as any).code === "23503" ||
|
||||||
|
(error as any).message?.includes("foreign key")
|
||||||
|
) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error:
|
error:
|
||||||
"User does not exist in authentication system. Please sign out and sign back in, then retry onboarding.",
|
"User does not exist in authentication system. Please sign out and sign back in, then retry onboarding.",
|
||||||
|
|
@ -140,7 +156,9 @@ export function createServer() {
|
||||||
}
|
}
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
error:
|
error:
|
||||||
(error as any).message || JSON.stringify(error) || "Unknown error",
|
(error as any).message ||
|
||||||
|
JSON.stringify(error) ||
|
||||||
|
"Unknown error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,12 +171,21 @@ export function createServer() {
|
||||||
|
|
||||||
app.post("/api/interests", async (req, res) => {
|
app.post("/api/interests", async (req, res) => {
|
||||||
const { user_id, interests } = req.body || {};
|
const { user_id, interests } = req.body || {};
|
||||||
if (!user_id || !Array.isArray(interests)) return res.status(400).json({ error: "invalid payload" });
|
if (!user_id || !Array.isArray(interests))
|
||||||
|
return res.status(400).json({ error: "invalid payload" });
|
||||||
try {
|
try {
|
||||||
await adminSupabase.from("user_interests").delete().eq("user_id", user_id);
|
await adminSupabase
|
||||||
|
.from("user_interests")
|
||||||
|
.delete()
|
||||||
|
.eq("user_id", user_id);
|
||||||
if (interests.length) {
|
if (interests.length) {
|
||||||
const rows = interests.map((interest: string) => ({ user_id, interest }));
|
const rows = interests.map((interest: string) => ({
|
||||||
const { error } = await adminSupabase.from("user_interests").insert(rows);
|
user_id,
|
||||||
|
interest,
|
||||||
|
}));
|
||||||
|
const { error } = await adminSupabase
|
||||||
|
.from("user_interests")
|
||||||
|
.insert(rows);
|
||||||
if (error) return res.status(500).json({ error: error.message });
|
if (error) return res.status(500).json({ error: error.message });
|
||||||
}
|
}
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
|
|
@ -170,9 +197,10 @@ export function createServer() {
|
||||||
app.post("/api/achievements/award", async (req, res) => {
|
app.post("/api/achievements/award", async (req, res) => {
|
||||||
const { user_id, achievement_names } = req.body || {};
|
const { user_id, achievement_names } = req.body || {};
|
||||||
if (!user_id) return res.status(400).json({ error: "user_id required" });
|
if (!user_id) return res.status(400).json({ error: "user_id required" });
|
||||||
const names: string[] = Array.isArray(achievement_names) && achievement_names.length
|
const names: string[] =
|
||||||
? achievement_names
|
Array.isArray(achievement_names) && achievement_names.length
|
||||||
: ["Welcome to AeThex"];
|
? achievement_names
|
||||||
|
: ["Welcome to AeThex"];
|
||||||
try {
|
try {
|
||||||
const { data: achievements, error: aErr } = await adminSupabase
|
const { data: achievements, error: aErr } = await adminSupabase
|
||||||
.from("achievements")
|
.from("achievements")
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
import { createClient } from "@supabase/supabase-js";
|
import { createClient } from "@supabase/supabase-js";
|
||||||
|
|
||||||
const SUPABASE_URL = process.env.SUPABASE_URL || process.env.VITE_SUPABASE_URL || "";
|
const SUPABASE_URL =
|
||||||
|
process.env.SUPABASE_URL || process.env.VITE_SUPABASE_URL || "";
|
||||||
const SUPABASE_SERVICE_ROLE = process.env.SUPABASE_SERVICE_ROLE || "";
|
const SUPABASE_SERVICE_ROLE = process.env.SUPABASE_SERVICE_ROLE || "";
|
||||||
|
|
||||||
if (!SUPABASE_URL) {
|
if (!SUPABASE_URL) {
|
||||||
console.warn("SUPABASE_URL not set for server");
|
console.warn("SUPABASE_URL not set for server");
|
||||||
}
|
}
|
||||||
if (!SUPABASE_SERVICE_ROLE) {
|
if (!SUPABASE_SERVICE_ROLE) {
|
||||||
console.warn("SUPABASE_SERVICE_ROLE not set for server (admin ops will fail)");
|
console.warn(
|
||||||
|
"SUPABASE_SERVICE_ROLE not set for server (admin ops will fail)",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const adminSupabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE, {
|
export const adminSupabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE, {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue