mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 11:59:11 +00:00
fix(web): add /machinery/new-session/... route, start auth flow from there
This commit is contained in:
parent
8fbf8f2519
commit
fe90c06b4e
3 changed files with 21 additions and 7 deletions
|
@ -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" />
|
||||
|
|
|
@ -10,7 +10,7 @@ const Landing = () => {
|
|||
const appShellProps = useAppShellProps();
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Redirect to="/servers" />;
|
||||
return <Redirect to="/servers" noThrow />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -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 />}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue