Skip to content

Commit

Permalink
(core) Include hash/fragment in post-login redirect URLs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
georgegevoian committed Apr 13, 2022
1 parent 20dd2fc commit 007a862
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/client/models/gristUrlState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 007a862

Please sign in to comment.