File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Navigate , useLocation } from 'react-router-dom' ;
22import { useAuth } from '@/lib/supabase/AuthProvider' ;
3- import { Loader2 } from 'lucide-react' ;
43
54export function RequireAuth ( { children } : { children : React . ReactNode } ) {
65 const { user, loading } = useAuth ( ) ;
76 const location = useLocation ( ) ;
87
9- if ( loading ) {
10- // Avoid a "blank screen" while Supabase loads/recovers the session.
11- return (
12- < div className = "min-h-screen flex items-center justify-center bg-background" >
13- < Loader2 className = "h-8 w-8 animate-spin text-primary" />
14- </ div >
15- ) ;
16- }
8+ if ( loading ) return null ;
179
1810 if ( ! user ) {
1911 return < Navigate to = "/login" state = { { from : location } } replace /> ;
Original file line number Diff line number Diff line change @@ -27,23 +27,13 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
2727 let mounted = true ;
2828
2929 const init = async ( ) => {
30- try {
31- const { data, error } = await supabase . auth . getSession ( ) ;
32- if ( ! mounted ) return ;
33- if ( error ) console . warn ( '[Auth] getSession error:' , error . message ) ;
34- setSession ( data . session ?? null ) ;
35- if ( data . session ) {
36- void hydrateSessionStore ( ) ;
37- void hydrateSettingsStore ( ) ;
38- }
39- } catch ( err ) {
40- // If local storage is corrupted (common), getSession can throw and we
41- // end up stuck in a blank screen. Fail open to the login route.
42- console . error ( '[Auth] getSession failed:' , err ) ;
43- if ( ! mounted ) return ;
44- setSession ( null ) ;
45- } finally {
46- if ( mounted ) setLoading ( false ) ;
30+ const { data } = await supabase . auth . getSession ( ) ;
31+ if ( ! mounted ) return ;
32+ setSession ( data . session ?? null ) ;
33+ setLoading ( false ) ;
34+ if ( data . session ) {
35+ void hydrateSessionStore ( ) ;
36+ void hydrateSettingsStore ( ) ;
4737 }
4838 } ;
4939
You can’t perform that action at this time.
0 commit comments