Skip to content

Commit b118e5f

Browse files
fix expired token experience
1 parent 179d7f9 commit b118e5f

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

packages/app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
"@apollo/react-hooks": "^3.1.3",
7474
"@babel/plugin-transform-destructuring": "^7.5.0",
7575
"@babel/preset-env": "^7.5.5",
76+
"@codesandbox/components": "0.0.1",
7677
"@codesandbox/executors": "^0.1.0",
7778
"@codesandbox/template-icons": "^1.1.0",
78-
"@codesandbox/components": "0.0.1",
7979
"@emmetio/codemirror-plugin": "^0.3.5",
8080
"@sentry/webpack-plugin": "^1.8.0",
8181
"@styled-system/css": "^5.0.23",
@@ -162,9 +162,9 @@
162162
"normalizr": "^3.2.3",
163163
"onigasm": "^2.2.1",
164164
"ot": "^0.0.15",
165-
"overmind": "^22.0.0-1580488381342",
165+
"overmind": "^23.0.0-1582189759083",
166166
"overmind-devtools": "^19.0.0",
167-
"overmind-react": "^23.0.0-1580488381342",
167+
"overmind-react": "^24.0.0-1582189759083",
168168
"phoenix": "^1.4.11",
169169
"postcss": "^7.0.26",
170170
"postcss-selector-parser": "^2.2.3",

packages/app/src/app/overmind/factories.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,27 @@ export const withLoadApp = <T>(
2828
actions.internal.setStoredSettings();
2929
effects.codesandboxApi.listen(actions.server.onCodeSandboxAPIMessage);
3030

31+
try {
32+
state.user = await effects.api.getCurrentUser();
33+
} catch (error) {
34+
actions.internal.handleError({
35+
message: '',
36+
error,
37+
});
38+
}
39+
40+
state.isAuthenticating = false;
41+
3142
if (state.jwt) {
32-
try {
33-
state.user = await effects.api.getCurrentUser();
34-
actions.internal.setPatronPrice();
35-
actions.internal.setSignedInCookie();
36-
effects.analytics.identify('signed_in', true);
37-
effects.analytics.setUserId(state.user.id);
38-
actions.internal.showUserSurveyIfNeeded();
39-
effects.live.connect();
40-
actions.userNotifications.internal.initialize();
41-
effects.api.preloadTemplates();
42-
} catch (error) {
43-
actions.internal.handleError({
44-
message: 'We had trouble with signing you in',
45-
error,
46-
});
47-
}
43+
actions.internal.setPatronPrice();
44+
actions.internal.setSignedInCookie();
45+
effects.analytics.identify('signed_in', true);
46+
effects.analytics.setUserId(state.user.id);
47+
actions.internal.showUserSurveyIfNeeded();
48+
effects.live.connect();
49+
actions.userNotifications.internal.initialize();
50+
effects.api.preloadTemplates();
4851
} else {
49-
effects.jwt.reset();
5052
effects.analytics.setAnonymousId();
5153
}
5254

@@ -55,7 +57,6 @@ export const withLoadApp = <T>(
5557
}
5658

5759
state.hasLoadedApp = true;
58-
state.isAuthenticating = false;
5960

6061
try {
6162
const response = await effects.http.get<{

packages/app/src/app/overmind/internalActions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ export const handleError: Action<{
407407
message: string;
408408
error: ApiError | Error;
409409
hideErrorMessage?: boolean;
410-
}> = ({ actions, effects }, { message, error, hideErrorMessage = false }) => {
410+
}> = (
411+
{ state, actions, effects },
412+
{ message, error, hideErrorMessage = false }
413+
) => {
411414
if (hideErrorMessage) {
412415
effects.analytics.logError(error);
413416
effects.notificationToast.add({
@@ -438,7 +441,7 @@ export const handleError: Action<{
438441

439442
if (response?.status === 401) {
440443
// Reset existing sign in info
441-
effects.jwt.reset();
444+
state.jwt = effects.jwt.reset();
442445
effects.analytics.setAnonymousId();
443446

444447
// Allow user to sign in again in notification

packages/app/src/app/pages/NewSandbox/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import Centered from '@codesandbox/common/lib/components/flex/Centered';
22
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
3-
import React, { FunctionComponent, useEffect } from 'react';
4-
import Media from 'react-media';
5-
63
import {
7-
CreateSandbox,
84
COLUMN_MEDIA_THRESHOLD,
5+
CreateSandbox,
96
} from 'app/components/CreateNewSandbox/CreateSandbox';
107
import { useOvermind } from 'app/overmind';
118
import { Navigation } from 'app/pages/common/Navigation';
9+
import React, { FunctionComponent, useEffect } from 'react';
10+
import Media from 'react-media';
1211

13-
import {MaxWidth} from './elements'
12+
import { MaxWidth } from './elements';
1413

1514
export const NewSandbox: FunctionComponent = () => {
1615
const {
16+
state: { isAuthenticating },
1717
actions: { sandboxPageMounted },
1818
} = useOvermind();
1919

2020
useEffect(() => {
2121
sandboxPageMounted();
2222
}, [sandboxPageMounted]);
2323

24+
if (isAuthenticating) {
25+
return null;
26+
}
27+
2428
return (
2529
<MaxWidth>
2630
<Margin horizontal={1.5} style={{ height: '100%' }} vertical={1.5}>

0 commit comments

Comments
 (0)