File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 198
198
}
199
199
200
200
let isUserAuthenticated = false ;
201
+ let expiredToken = "" ;
202
+
201
203
function removeCookie ( cookieName ) {
202
204
document . cookie = cookieName + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;" ;
203
205
}
216
218
const checkUserAuth = async ( ) => {
217
219
try {
218
220
const token = getCookieValue ( "provider_token" ) ;
219
- if ( ! token ) { // cookie doesn't exist, user logged out of cloud
221
+ if ( ! token || token === expiredToken ) { // cookie doesn't exist or has expired (due to user logout)
220
222
if ( isUserAuthenticated ) {
221
223
showSignInButton ( ) ;
222
224
isUserAuthenticated = false ;
223
225
}
224
- throw new Error ( "no cookie to authenticate " ) ;
226
+ throw new Error ( "missing or expired cookie " ) ;
225
227
}
226
228
const re = await fetch ( "https://cloud.layer5.io/api/identity/users/profile" , {
227
229
method : 'GET' ,
230
232
} ,
231
233
} ) ;
232
234
235
+ if ( res . status === 401 ) { // cookie has expired
236
+ expiredToken = token ;
237
+ throw new Error ( "unauthorized" ) ;
238
+ }
233
239
if ( re . status !== 200 ) {
234
240
throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
235
241
}
You can’t perform that action at this time.
0 commit comments