Persist relative return-to path for post-login redirect
Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
@@ -49,6 +49,7 @@ export default {
|
|||||||
// }
|
// }
|
||||||
async beforeRouteEnter(to, from, next) {
|
async beforeRouteEnter(to, from, next) {
|
||||||
const loginStore = useLoginStore();
|
const loginStore = useLoginStore();
|
||||||
|
const relativeReturnTo = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
||||||
|
|
||||||
if (!getCookie("isLuciaLoggedIn")) {
|
if (!getCookie("isLuciaLoggedIn")) {
|
||||||
if (getCookie('luciaRefreshToken')) {
|
if (getCookie('luciaRefreshToken')) {
|
||||||
@@ -61,7 +62,7 @@ export default {
|
|||||||
next({
|
next({
|
||||||
path: '/login',
|
path: '/login',
|
||||||
query: {
|
query: {
|
||||||
'return-to': btoa(window.location.href),
|
'return-to': btoa(relativeReturnTo),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ export default {
|
|||||||
next({
|
next({
|
||||||
path: '/login',
|
path: '/login',
|
||||||
query: {
|
query: {
|
||||||
'return-to': btoa(window.location.href),
|
'return-to': btoa(relativeReturnTo),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,4 +91,15 @@ describe('MainContainer beforeRouteEnter', () => {
|
|||||||
|
|
||||||
expect(next).toHaveBeenCalled();
|
expect(next).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stores a relative return-to path when redirecting to login', async () => {
|
||||||
|
window.history.replaceState({}, '', '/discover/log/1/map?view=summary#node-2');
|
||||||
|
|
||||||
|
await callGuard();
|
||||||
|
|
||||||
|
const redirectArg = next.mock.calls[0][0];
|
||||||
|
const returnTo = redirectArg.query['return-to'];
|
||||||
|
|
||||||
|
expect(atob(returnTo)).toBe('/discover/log/1/map?view=summary#node-2');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user