(core) Include hash/fragment in post-login redirect URLs

Summary: Also cleans up login URLs by excluding params and hashes.

Test Plan: Client and server tests.

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D3378
This commit is contained in:
George Gevoian 2022-04-12 23:17:44 -07:00
parent 20dd2fc70d
commit 007a862333

View File

@ -89,16 +89,18 @@ export function getLoginOrSignupUrl(nextUrl: string = _getCurrentUrl()): string
// "/signed-out" page, in which case it returns the home page ("/"). // "/signed-out" page, in which case it returns the home page ("/").
// This is a good URL to use for a post-login redirect. // This is a good URL to use for a post-login redirect.
function _getCurrentUrl(): string { function _getCurrentUrl(): string {
if (window.location.pathname.endsWith('/signed-out')) { return '/'; } const {hash, pathname, search} = new URL(window.location.href);
if (pathname.endsWith('/signed-out')) { return '/'; }
const {pathname, search} = new URL(window.location.href); return parseFirstUrlPart('o', pathname).path + search + hash;
return parseFirstUrlPart('o', pathname).path + search;
} }
// Returns the URL for the given login page, with 'next' param optionally set. // Returns the URL for the given login page, with 'next' param optionally set.
function _getLoginLogoutUrl(page: 'login'|'logout'|'signin'|'signup', nextUrl?: string | null): string { function _getLoginLogoutUrl(page: 'login'|'logout'|'signin'|'signup', nextUrl?: string | null): string {
const startUrl = new URL(window.location.href); const startUrl = new URL(window.location.href);
startUrl.pathname = addOrgToPath('', window.location.href, true) + '/' + page; startUrl.pathname = addOrgToPath('', window.location.href, true) + '/' + page;
startUrl.search = '';
startUrl.hash = '';
if (nextUrl) { startUrl.searchParams.set('next', nextUrl); } if (nextUrl) { startUrl.searchParams.set('next', nextUrl); }
return startUrl.href; return startUrl.href;
} }