Spaces:
Running
Running
fix: enhance error handling in Nav component and provide fallback for Supabase client initialization
Browse files- web/components/nav.tsx +32 -14
- web/lib/supabase/client.ts +2 -2
web/components/nav.tsx
CHANGED
|
@@ -29,21 +29,39 @@ export function Nav() {
|
|
| 29 |
const hasTeam = !!userTeam;
|
| 30 |
|
| 31 |
useEffect(() => {
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
setLoaded(true);
|
| 46 |
-
}
|
| 47 |
}, []);
|
| 48 |
|
| 49 |
async function handleSignOut() {
|
|
|
|
| 29 |
const hasTeam = !!userTeam;
|
| 30 |
|
| 31 |
useEffect(() => {
|
| 32 |
+
try {
|
| 33 |
+
const supabase = createClient();
|
| 34 |
+
supabase.auth.getUser().then(async ({ data, error }) => {
|
| 35 |
+
if (error) {
|
| 36 |
+
console.error("Auth error:", error);
|
| 37 |
+
setLoaded(true);
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
+
const user = data.user;
|
| 41 |
+
setUserEmail(user?.email || null);
|
| 42 |
+
if (user) {
|
| 43 |
+
try {
|
| 44 |
+
const { data: profile } = await supabase
|
| 45 |
+
.from("profiles")
|
| 46 |
+
.select("role, team_id")
|
| 47 |
+
.eq("id", user.id)
|
| 48 |
+
.single();
|
| 49 |
+
setUserRole(profile?.role || "user");
|
| 50 |
+
setUserTeam(profile?.team_id || null);
|
| 51 |
+
} catch (err) {
|
| 52 |
+
console.error("Profile error:", err);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
setLoaded(true);
|
| 56 |
+
}).catch(err => {
|
| 57 |
+
console.error("Unexpected error:", err);
|
| 58 |
+
setLoaded(true);
|
| 59 |
+
});
|
| 60 |
+
} catch (err) {
|
| 61 |
+
console.error("Supabase client init error:", err);
|
| 62 |
+
// Fallback for when env variables are not found/configured
|
| 63 |
setLoaded(true);
|
| 64 |
+
}
|
| 65 |
}, []);
|
| 66 |
|
| 67 |
async function handleSignOut() {
|
web/lib/supabase/client.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { createBrowserClient } from "@supabase/ssr";
|
|
| 2 |
|
| 3 |
export function createClient() {
|
| 4 |
return createBrowserClient(
|
| 5 |
-
process.env.NEXT_PUBLIC_SUPABASE_URL
|
| 6 |
-
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
|
| 7 |
{
|
| 8 |
auth: {
|
| 9 |
autoRefreshToken: true,
|
|
|
|
| 2 |
|
| 3 |
export function createClient() {
|
| 4 |
return createBrowserClient(
|
| 5 |
+
process.env.NEXT_PUBLIC_SUPABASE_URL || "https://dummy-project.supabase.co",
|
| 6 |
+
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY || "dummy-anon-key",
|
| 7 |
{
|
| 8 |
auth: {
|
| 9 |
autoRefreshToken: true,
|