Skip to content

Commit

Permalink
MOBILE-4362 auth: Fix redirect to other site in slow devices
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Oct 19, 2023
1 parent b982a96 commit 1250779
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/features/mainmenu/guards/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class CoreMainMenuAuthGuard implements CanLoad, CanActivate {

// Pass redirect data (if any and belongs to same site).
let redirect = CoreApp.consumeMemoryRedirect();
if (!redirect?.timemodified || Date.now() - redirect.timemodified > 20000 || redirect.siteId !== siteId) {
if (redirect?.siteId !== siteId) {
redirect = null;
}

Expand Down
6 changes: 0 additions & 6 deletions src/core/guards/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,10 @@ export class CoreRedirectGuard implements CanLoad, CanActivate {
*/
private async guard(): Promise<true | UrlTree> {
const redirect = CoreApp.consumeMemoryRedirect();

if (!redirect) {
return true;
}

// Only accept the redirect if it was stored less than 20 seconds ago.
if (!redirect.timemodified || Date.now() - redirect.timemodified > 20000) {
return true;
}

// Redirect to site path.
if (redirect.siteId && redirect.siteId !== CoreConstants.NO_SITE_ID) {
const redirectData: CoreRedirectPayload = {
Expand Down
5 changes: 5 additions & 0 deletions src/core/services/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ export class CoreAppProvider {

this.forgetRedirect();

if (redirect && (!redirect.timemodified || Date.now() - redirect.timemodified > 300000)) {
// Redirect data is only valid for 5 minutes, discard it.
return null;
}

return redirect;
}

Expand Down

0 comments on commit 1250779

Please sign in to comment.