Public Access
fix(session): keep the hash on the login round trip
This commit is contained in:
1 parent
8e31eafc06
commit
c6d76b4cb5
2 files changed
+10
-2
No files matched your search
@@ -6,11 +6,11 @@ import useSession from '../hooks/useSession.js';
|
||||
* After a logout it only opens the login page, so the next login does not land on the page of the last user.
|
||||
*/
|
||||
export default function RequireSession() {
|
||||
const {pathname, search} = useLocation();
|
||||
const {pathname, search, hash} = useLocation();
|
||||
const {active, endReason} = useSession();
|
||||
|
||||
if (active) return <Outlet/>;
|
||||
const from = pathname + search;
|
||||
const from = pathname + search + hash;
|
||||
if (endReason === 'logout') return <Navigate to="/login" replace/>;
|
||||
return <Navigate to="/login" replace state={endReason === 'expired' ? {sessionExpired: true, from} : {from}}/>;
|
||||
}
|
||||
@@ -30,6 +30,14 @@ describe('RequireSession', () => {
|
||||
expect(at(router)).toEqual({path: '/login', state: {from: '/library?status=PLAYING'}});
|
||||
});
|
||||
|
||||
// The bookmarklet sends its list in #data; it must survive the login.
|
||||
it('keeps the hash of the deep link', async () => {
|
||||
const router = renderAt('/library#data=abc');
|
||||
|
||||
expect(await screen.findByText('login')).toBeTruthy();
|
||||
expect(at(router)).toEqual({path: '/login', state: {from: '/library#data=abc'}});
|
||||
});
|
||||
|
||||
it('shows the page with a session', () => {
|
||||
markSession();
|
||||
renderAt('/library');
|
||||
|
||||
Reference in new issue
Block a user