Skip to content

Commit c155138

Browse files
committed
add callback to accept auth tokens as part of vsc login
1 parent 4e17ff7 commit c155138

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { useEffect } from 'react';
2+
import { useDispatch } from 'react-redux';
3+
import { useLocation, useNavigate } from 'react-router';
4+
import SessionActions from 'src/commons/application/actions/SessionActions';
5+
import { parseQuery } from 'src/commons/utils/QueryHelper';
6+
7+
const LoginVscodeCallback: React.FC = () => {
8+
const navigate = useNavigate();
9+
const dispatch = useDispatch();
10+
const location = useLocation();
11+
12+
const { access_token: accessToken, refresh_token: refreshToken } = parseQuery(location.search);
13+
14+
useEffect(() => {
15+
if (accessToken && refreshToken) {
16+
dispatch(
17+
SessionActions.setTokens({
18+
accessToken: accessToken,
19+
refreshToken: refreshToken
20+
})
21+
);
22+
dispatch(SessionActions.fetchUserAndCourse());
23+
navigate(`/welcome`);
24+
}
25+
}, []);
26+
27+
return <> </>;
28+
};
29+
30+
// react-router lazy loading
31+
// https://reactrouter.com/en/main/route/lazy
32+
export const Component = LoginVscodeCallback;
33+
Component.displayName = 'Login';
34+
35+
export default LoginVscodeCallback;

src/routes/routerConfig.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { GuardedRoute } from './routeGuard';
2525
const Login = () => import('../pages/login/Login');
2626
const LoginPage = () => import('../pages/login/LoginPage');
2727
const LoginCallback = () => import('../pages/login/LoginCallback');
28+
const LoginVscodeCallback = () => import('../pages/login/LoginVscodeCallback');
2829
const NusLogin = () => import('../pages/login/NusLogin');
2930
const Contributors = () => import('../pages/contributors/Contributors');
3031
const GitHubCallback = () => import('../pages/githubCallback/GitHubCallback');
@@ -128,7 +129,10 @@ export const getFullAcademyRouterConfig = ({
128129
{
129130
path: 'login',
130131
lazy: Login,
131-
children: [{ path: 'callback', lazy: LoginCallback }]
132+
children: [
133+
{ path: 'callback', lazy: LoginCallback },
134+
{ path: 'vscode_callback', lazy: LoginVscodeCallback }
135+
]
132136
},
133137
{ path: 'welcome', lazy: Welcome, loader: welcomeLoader },
134138
{ path: 'courses', element: <Navigate to="/" /> },

0 commit comments

Comments
 (0)