Skip to content

Commit

Permalink
fix(Login): Add redirectUrl to Google login url (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Sep 9, 2022
1 parent cb30da0 commit 1446076
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/app/login/login-home/login-home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class MockUserService {
return false;
}
getRedirectUrl(): string {
return '';
return '/path/to/redirect';
}
}

Expand All @@ -30,13 +30,16 @@ export class MockConfigService {
observer.complete();
});
}
getContextPath(): string {
return '/wise';
}
getRecaptchaPublicKey(): string {
return '';
}
}

let component: LoginHomeComponent;
describe('LoginHomeComponent', () => {
let component: LoginHomeComponent;
let fixture: ComponentFixture<LoginHomeComponent>;
beforeEach(
waitForAsync(() => {
Expand All @@ -57,8 +60,15 @@ describe('LoginHomeComponent', () => {
component = fixture.componentInstance;
fixture.detectChanges();
});
getRedirectUrl();
});

it('should create', () => {
expect(component).toBeTruthy();
function getRedirectUrl() {
describe('getRedirectUrl()', () => {
it('should add redirectUrl to Google login url', () => {
expect(component.getRedirectUrl('google')).toEqual(
'/wise/api/google-login?redirectUrl=/path/to/redirect'
);
});
});
});
}
8 changes: 6 additions & 2 deletions src/app/login/login-home/login-home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ export class LoginHomeComponent implements OnInit {
getRedirectUrl(social: string): string {
let redirectUrl = '';
if (social === 'google') {
redirectUrl = `${this.configService.getContextPath()}/api/google-login`;
redirectUrl = `${this.configService.getContextPath()}/api/google-login?redirectUrl=${this.userService.getRedirectUrl()}`;
} else {
redirectUrl = this.userService.getRedirectUrl();
}
if (this.accessCode !== '') {
redirectUrl = `${redirectUrl}?accessCode=${this.accessCode}`;
redirectUrl = this.appendAccessCodeParameter(redirectUrl);
}
return redirectUrl;
}

private appendAccessCodeParameter(url: string): string {
return `${url}${url.includes('?') ? '&' : '?'}accessCode=${this.accessCode}`;
}
}

0 comments on commit 1446076

Please sign in to comment.