From 007a862333cf3aeb6feaa63042c568e1ecd38871 Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Tue, 12 Apr 2022 23:17:44 -0700 Subject: [PATCH] (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 --- app/client/models/gristUrlState.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/client/models/gristUrlState.ts b/app/client/models/gristUrlState.ts index e1be9441..1d01606a 100644 --- a/app/client/models/gristUrlState.ts +++ b/app/client/models/gristUrlState.ts @@ -89,16 +89,18 @@ export function getLoginOrSignupUrl(nextUrl: string = _getCurrentUrl()): string // "/signed-out" page, in which case it returns the home page ("/"). // This is a good URL to use for a post-login redirect. 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; + return parseFirstUrlPart('o', pathname).path + search + hash; } // Returns the URL for the given login page, with 'next' param optionally set. function _getLoginLogoutUrl(page: 'login'|'logout'|'signin'|'signup', nextUrl?: string | null): string { const startUrl = new URL(window.location.href); startUrl.pathname = addOrgToPath('', window.location.href, true) + '/' + page; + startUrl.search = ''; + startUrl.hash = ''; if (nextUrl) { startUrl.searchParams.set('next', nextUrl); } return startUrl.href; }