@@ -22,18 +22,16 @@ export default function AuthWrapper({ children }: AuthWrapperProps) {
2222 async function checkAuth ( ) {
2323 try {
2424 setError ( null ) ;
25-
26- // Always handle incoming redirect first - this is necessary to restore sessions
25+
2726 // The library uses this to restore session state from localStorage
28- // Set restorePreviousSession to true to enable session restoration on page refresh
2927 const redirectInfo = await handleIncomingRedirect ( {
3028 restorePreviousSession : true ,
3129 } ) ;
32-
30+
3331 // Get the session instance after handling redirect
3432 const session = getDefaultSession ( ) ;
35-
36- // development logs (will remove later)
33+
34+ // development logs (I will remove later)
3735 console . log ( "=== Session Check ===" ) ;
3836 console . log ( "Redirect Info:" , redirectInfo ) ;
3937 console . log ( "Session Info:" , session . info ) ;
@@ -45,10 +43,9 @@ export default function AuthWrapper({ children }: AuthWrapperProps) {
4543 console . log ( "Expiration Date:" , expDate . toISOString ( ) ) ;
4644 console . log ( "Is Expired:" , expDate <= new Date ( ) ) ;
4745 }
48-
49- // Check if we have a valid session
46+
5047 let isLoggedIn = session . info . isLoggedIn && ! ! session . info . webId ;
51-
48+
5249 // Check expiration if session exists
5350 if ( isLoggedIn && session . info . expirationDate ) {
5451 const expirationDate = new Date ( session . info . expirationDate ) ;
@@ -58,9 +55,9 @@ export default function AuthWrapper({ children }: AuthWrapperProps) {
5855 isLoggedIn = false ;
5956 }
6057 }
61-
62-
63-
58+
59+
60+
6461 setIsAuthenticated ( isLoggedIn ) ;
6562 } catch ( err ) {
6663 console . error ( "Auth check failed:" , err ) ;
@@ -78,23 +75,23 @@ export default function AuthWrapper({ children }: AuthWrapperProps) {
7875
7976 // Re-check authentication state periodically in case user logs in from another tab
8077 useEffect ( ( ) => {
81- if ( ! isAuthenticated && ! error ) {
82- const interval = setInterval ( async ( ) => {
83- try {
84- const redirectInfo = await handleIncomingRedirect ( {
85- restorePreviousSession : true ,
86- } ) ;
87- const session = getDefaultSession ( ) ;
78+ if ( ! isAuthenticated && ! error ) {
79+ const interval = setInterval ( async ( ) => {
80+ try {
81+ const redirectInfo = await handleIncomingRedirect ( {
82+ restorePreviousSession : true ,
83+ } ) ;
84+ const session = getDefaultSession ( ) ;
8885 if ( session . info . isLoggedIn ) {
89- // Log authentication response after redirect (from polling )
86+ // more logs (i will remove them later )
9087 console . log ( "=== Authentication Response (from polling) ===" ) ;
9188 console . log ( "Redirect Info:" , redirectInfo ) ;
9289 console . log ( "Session Info:" , session . info ) ;
9390 console . log ( "WebID:" , session . info . webId ) ;
9491 console . log ( "Is Logged In:" , session . info . isLoggedIn ) ;
9592 console . log ( "Session ID:" , session . info . sessionId ) ;
9693 console . log ( "==============================================" ) ;
97-
94+
9895 setIsAuthenticated ( true ) ;
9996 setError ( null ) ;
10097 }
@@ -111,7 +108,7 @@ export default function AuthWrapper({ children }: AuthWrapperProps) {
111108 setError ( null ) ;
112109 setIsChecking ( true ) ;
113110 setIsAuthenticated ( null ) ;
114- // Trigger re-check
111+
115112 handleIncomingRedirect ( { restorePreviousSession : true } )
116113 . then ( ( ) => {
117114 const session = getDefaultSession ( ) ;
0 commit comments