Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app/pages/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
}}
/>
<Route
loader={() => {
loader={({ request }) => {
if (getFallbackSession()) {
return redirect(getHomePath());
}
const url = new URL(request.url);
const redirectAfterLogin = url.searchParams.get('redirect_after_login');
if (redirectAfterLogin) {
setAfterLoginRedirectPath(redirectAfterLogin);
}

return null;
}}
Expand Down
16 changes: 15 additions & 1 deletion src/app/pages/auth/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getLoginPath, getRegisterPath, withSearchParam } from '../../pathUtils'
import { usePathWithOrigin } from '../../../hooks/usePathWithOrigin';
import { LoginPathSearchParams } from '../../paths';
import { useClientConfig } from '../../../hooks/useClientConfig';
import { setAfterLoginRedirectPath } from '../../afterLoginRedirectPath';

const getLoginTokenSearchParam = () => {
// when using hasRouter query params in existing route
Expand All @@ -30,6 +31,7 @@ const useLoginSearchParams = (searchParams: URLSearchParams): LoginPathSearchPar
username: searchParams.get('username') ?? undefined,
email: searchParams.get('email') ?? undefined,
loginToken: searchParams.get('loginToken') ?? undefined,
redirect_after_login: searchParams.get('redirect_after_login') ?? undefined,
}),
[searchParams]
);
Expand All @@ -54,6 +56,18 @@ export function Login() {

const parsedFlows = useParsedLoginFlows(loginFlows.flows);

React.useEffect(() => {
if (loginSearchParams.redirect_after_login) {
setAfterLoginRedirectPath(loginSearchParams.redirect_after_login);
}
}, [loginSearchParams.redirect_after_login]);

const registerPath = loginSearchParams.redirect_after_login
? withSearchParam(getRegisterPath(server), {
redirect_after_login: loginSearchParams.redirect_after_login,
})
: getRegisterPath(server);

return (
<Box direction="Column" gap="500">
<Text size="H2" priority="400">
Expand Down Expand Up @@ -92,7 +106,7 @@ export function Login() {
</>
)}
<Text align="Center">
Do not have an account? <Link to={getRegisterPath(server)}>Register</Link>
Do not have an account? <Link to={registerPath}>Register</Link>
</Text>
</Box>
);
Expand Down
17 changes: 16 additions & 1 deletion src/app/pages/auth/register/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import { SupportedUIAFlowsLoader } from '../../../components/SupportedUIAFlowsLo
import { getLoginPath } from '../../pathUtils';
import { usePathWithOrigin } from '../../../hooks/usePathWithOrigin';
import { RegisterPathSearchParams } from '../../paths';
import { setAfterLoginRedirectPath } from '../../afterLoginRedirectPath';
import { withSearchParam } from '../../pathUtils';

const useRegisterSearchParams = (searchParams: URLSearchParams): RegisterPathSearchParams =>
useMemo(
() => ({
username: searchParams.get('username') ?? undefined,
email: searchParams.get('email') ?? undefined,
token: searchParams.get('token') ?? undefined,
redirect_after_login: searchParams.get('redirect_after_login') ?? undefined,
}),
[searchParams]
);
Expand All @@ -33,6 +36,18 @@ export function Register() {
// redirect to /login because only that path handle m.login.token
const ssoRedirectUrl = usePathWithOrigin(getLoginPath(server));

React.useEffect(() => {
if (registerSearchParams.redirect_after_login) {
setAfterLoginRedirectPath(registerSearchParams.redirect_after_login);
}
}, [registerSearchParams.redirect_after_login]);

const loginPath = registerSearchParams.redirect_after_login
? withSearchParam(getLoginPath(server), {
redirect_after_login: registerSearchParams.redirect_after_login,
})
: getLoginPath(server);

return (
<Box direction="Column" gap="500">
<Text size="H2" priority="400">
Expand Down Expand Up @@ -91,7 +106,7 @@ export function Register() {
</>
)}
<Text align="Center">
Already have an account? <Link to={getLoginPath(server)}>Login</Link>
Already have an account? <Link to={loginPath}>Login</Link>
</Text>
</Box>
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export type LoginPathSearchParams = {
username?: string;
email?: string;
loginToken?: string;
redirect_after_login?: string;
};
export const LOGIN_PATH = '/login/:server?/';

export type RegisterPathSearchParams = {
username?: string;
email?: string;
token?: string;
redirect_after_login?: string;
};
export const REGISTER_PATH = '/register/:server?/';

Expand Down
Loading