Add Supabase configuration check in AuthContext
cgen-bd43561f1b244b20b69dc5c27a2c9be9
This commit is contained in:
parent
d090e9332e
commit
7108729a80
1 changed files with 17 additions and 7 deletions
|
|
@ -32,6 +32,13 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Check if Supabase is configured
|
||||
if (!isSupabaseConfigured) {
|
||||
console.warn('Supabase is not configured. Please set up your environment variables.');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get initial session
|
||||
supabase.auth.getSession().then(({ data: { session } }) => {
|
||||
setSession(session);
|
||||
|
|
@ -40,6 +47,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||
fetchUserProfile(session.user.id);
|
||||
}
|
||||
setLoading(false);
|
||||
}).catch((error) => {
|
||||
console.error('Error getting session:', error);
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
// Listen for auth changes
|
||||
|
|
@ -48,7 +58,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||
} = supabase.auth.onAuthStateChange(async (event, session) => {
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
|
||||
|
||||
if (session?.user) {
|
||||
await fetchUserProfile(session.user.id);
|
||||
} else {
|
||||
|
|
@ -58,14 +68,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||
|
||||
// Show toast notifications for auth events
|
||||
if (event === 'SIGNED_IN') {
|
||||
aethexToast.success({
|
||||
title: 'Welcome back!',
|
||||
description: 'Successfully signed in to AeThex OS'
|
||||
aethexToast.success({
|
||||
title: 'Welcome back!',
|
||||
description: 'Successfully signed in to AeThex OS'
|
||||
});
|
||||
} else if (event === 'SIGNED_OUT') {
|
||||
aethexToast.info({
|
||||
title: 'Signed out',
|
||||
description: 'Come back soon!'
|
||||
aethexToast.info({
|
||||
title: 'Signed out',
|
||||
description: 'Come back soon!'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue