mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 18:09:09 +00:00
Improve pre- and post-auth redirect flows (#180)
* fix(web): add /machinery/new-session/... route, start auth flow from there * fix(api): change redirect to path-based format * fix(api): remove extra / from login-callback redirect * fix(web): /auth/login should skip flows if isAuthenticated is true
This commit is contained in:
parent
8fbf8f2519
commit
fd02dad62b
5 changed files with 33 additions and 11 deletions
|
@ -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
Add a link
Reference in a new issue