fix(web): add /machinery/new-session/... route, start auth flow from there

This commit is contained in:
41666 2021-03-14 15:54:30 -04:00
parent 8fbf8f2519
commit fe90c06b4e
3 changed files with 21 additions and 7 deletions

View file

@ -31,6 +31,10 @@ export const AppRouter = () => {
<RouteWrapper component={PickerPage} path="/s/:serverID" />
<RouteWrapper component={MachineryNewSession} path="/machinery/new-session" />
<RouteWrapper
component={MachineryNewSession}
path="/machinery/new-session/:sessionID"
/>
<RouteWrapper component={MachineryLogout} path="/machinery/logout" />
<RouteWrapper component={MachineryBotJoin} path="/machinery/bot-join" />
<RouteWrapper component={MachineryBotJoin} path="/machinery/bot-join/:serverID" />

View file

@ -10,7 +10,7 @@ const Landing = () => {
const appShellProps = useAppShellProps();
if (isAuthenticated) {
return <Redirect to="/servers" />;
return <Redirect to="/servers" noThrow />;
}
return (

View file

@ -1,22 +1,32 @@
import { Redirect } from '@reach/router';
import * as React from 'react';
import { useSessionContext } from '../../contexts/session/SessionContext';
import { Title } from '../../utils/metaTitle';
const NewSession = () => {
const NewSession = (props: { sessionID: string }) => {
const session = useSessionContext();
const [postauthUrl, setPostauthUrl] = React.useState('/servers');
React.useEffect(() => {
const url = new URL(window.location.href);
const id = url.searchParams.get('session_id');
const id = props.sessionID || url.searchParams.get('session_id');
if (id) {
localStorage.setItem('rp_session_key', id);
session.setSession({ sessionID: id });
const redirectUrl = localStorage.getItem('rp_postauth_redirect');
window.location.href = redirectUrl || '/';
const storedPostauthUrl = localStorage.getItem('rp_postauth_redirect');
if (storedPostauthUrl) {
setPostauthUrl(storedPostauthUrl);
localStorage.removeItem('rp_postauth_redirect');
}
});
}
}, [setPostauthUrl, props.sessionID, session]);
return (
<>
<Title title="Logging you into Roleypoly..." />
<div>Redirecting you...</div>
<div>Logging you into Roleypoly...</div>
{session.isAuthenticated && <Redirect to={postauthUrl} noThrow replace />}
</>
);
};