Skip to content

Commit d9a6584

Browse files
committed
Fix sign in unauthorized handling
We now handle it more clearly (so only unauthorized requests will sign you out) and we properly reset the state to make the dashboard go back to the sign in panel Fixes codesandbox#2198 Fixes codesandbox#2217 Fixes codesandbox#2234 Fixes codesandbox#2289
1 parent 160b340 commit d9a6584

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

packages/app/src/app/store/actions.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,13 @@ export function getUser({ api, path }) {
364364
return api
365365
.get('/users/current')
366366
.then(data => path.success({ user: data }))
367-
.catch(() => path.error());
367+
.catch(e => {
368+
if (e.response.status === 401) {
369+
return path.unauthorized();
370+
}
371+
372+
return path.error();
373+
});
368374
}
369375

370376
export function connectWebsocket({ socket }) {
@@ -380,8 +386,9 @@ export function setJwtFromStorage({ jwt, state }) {
380386
state.set('jwt', jwt.get() || null);
381387
}
382388

383-
export function removeJwtFromStorage({ jwt }) {
389+
export function removeJwtFromStorage({ jwt, state }) {
384390
jwt.reset();
391+
state.set('jwt', null);
385392
}
386393

387394
export function setSignedInCookie({ props }) {

packages/app/src/app/store/factories.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ export function withLoadApp(continueSequence) {
128128
],
129129
error: [
130130
addNotification(
131-
'Your session seems to be expired, please log in again...',
131+
"We weren't able to sign you in, this could be due to a flaky connection or something on our server. Please try again in a minute.",
132+
'error'
133+
),
134+
],
135+
unauthorized: [
136+
addNotification(
137+
'Your session seems to be expired, please try to log in again...',
132138
'error'
133139
),
134140
actions.removeJwtFromStorage,

packages/app/src/app/store/sequences.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ export const signIn = [
453453
setupNotifications,
454454
refetchSandboxInfo,
455455
],
456+
unauthorized: [
457+
factories.addNotification('Github Authentication Error', 'error'),
458+
],
456459
error: [
457460
factories.addNotification('Github Authentication Error', 'error'),
458461
],
@@ -473,7 +476,6 @@ export const signOut = [
473476
false: [],
474477
},
475478
actions.signOut,
476-
set(state`jwt`, null),
477479
actions.removeJwtFromStorage,
478480
set(state`user.id`, null),
479481
set(state`user.email`, null),

0 commit comments

Comments
 (0)