Skip to content

Commit 6093b43

Browse files
fix(ENG-10262): fixed encoding for login url
1 parent ae6fc32 commit 6093b43

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/app/core/services/auth.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { inject, Injectable, PLATFORM_ID } from '@angular/core';
88
import { SignUpModel } from '@core/models/sign-up.model';
99
import { ENVIRONMENT } from '@core/provider/environment.provider';
1010
import { ClearCurrentUser } from '@osf/core/store/user';
11-
import { urlParam } from '@osf/shared/helpers/url-param.helper';
11+
import { localUrlParam, urlParam } from '@osf/shared/helpers/url-param.helper';
1212
import { JsonApiService } from '@osf/shared/services/json-api.service';
1313
import { LoaderService } from '@osf/shared/services/loader.service';
1414

@@ -41,7 +41,14 @@ export class AuthService {
4141
}
4242

4343
this.loaderService.show();
44-
const loginUrl = `${this.casUrl}/login?${urlParam({ service: `${this.webUrl}/login`, next: window.location.href })}`;
44+
let loginUrl = null;
45+
if (this.environment.webUrl.includes('localhost')) {
46+
// CAS should handle auth instead of angular, so we need to pass the next param
47+
// in the service param to ensure the user is redirected back to the correct page after login
48+
loginUrl = `${this.casUrl}/login?${localUrlParam({ service: `${this.webUrl.replace('4200', '5000')}/login`, next: window.location.href })}`;
49+
} else {
50+
loginUrl = `${this.casUrl}/login?${urlParam({ service: `${this.webUrl}/login`, next: window.location.href })}`;
51+
}
4552
window.location.href = loginUrl;
4653
}
4754

src/app/shared/helpers/url-param.helper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,15 @@ export const urlParam = (params: Record<string, string>) => {
33
.map((entry) => entry.map((comp) => encodeURIComponent(comp)).join('='))
44
.join('&');
55
};
6+
7+
export const localUrlParam = (params: { service: string; next?: string }): string => {
8+
const { service, next } = params;
9+
10+
if (!next) {
11+
return `service=${encodeURIComponent(service)}`;
12+
}
13+
14+
const encodedNext = encodeURIComponent(next);
15+
const valueAfterService = `${service}?next=${encodedNext}`;
16+
return `service=${encodeURIComponent(valueAfterService)}`;
17+
};

0 commit comments

Comments
 (0)