mirror of
https://github.com/docmost/docmost.git
synced 2026-05-16 05:44:04 +08:00
fix: redirect to original page after re-authentication (#1959)
* fix: redirect to original page after re-authentication When a session expires, the current URL is now preserved as a query parameter on the login page. After successful login (including MFA flows), the user is redirected back to their original page instead of always landing on /home. * secure --------- Co-authored-by: Julien Fontanet <julien.fontanet@isonoe.net>
This commit is contained in:
@@ -68,10 +68,14 @@ function redirectToLogin() {
|
||||
APP_ROUTE.AUTH.SIGNUP,
|
||||
APP_ROUTE.AUTH.FORGOT_PASSWORD,
|
||||
APP_ROUTE.AUTH.PASSWORD_RESET,
|
||||
APP_ROUTE.AUTH.MFA_CHALLENGE,
|
||||
APP_ROUTE.AUTH.MFA_SETUP_REQUIRED,
|
||||
"/invites",
|
||||
];
|
||||
if (!exemptPaths.some((path) => window.location.pathname.startsWith(path))) {
|
||||
window.location.href = APP_ROUTE.AUTH.LOGIN;
|
||||
const redirectTo = window.location.pathname;
|
||||
const params = new URLSearchParams({ redirect: redirectTo });
|
||||
window.location.href = `${APP_ROUTE.AUTH.LOGIN}?${params.toString()}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,4 +29,20 @@ const APP_ROUTE = {
|
||||
},
|
||||
};
|
||||
|
||||
export function getPostLoginRedirect(): string {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const redirect = params.get("redirect");
|
||||
if (redirect) {
|
||||
try {
|
||||
const resolved = new URL(redirect, window.location.origin);
|
||||
if (resolved.origin === window.location.origin) {
|
||||
return resolved.pathname + resolved.search + resolved.hash;
|
||||
}
|
||||
} catch {
|
||||
// malformed URL, fall through to default
|
||||
}
|
||||
}
|
||||
return APP_ROUTE.HOME;
|
||||
}
|
||||
|
||||
export default APP_ROUTE;
|
||||
|
||||
Reference in New Issue
Block a user