Skip to content

Commit 62082fc

Browse files
feat: TT-577 get profile pic from Google account
1 parent 6563256 commit 62082fc

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

src/app/modules/login/services/login.service.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
22
import { TestBed } from '@angular/core/testing';
3-
import { SocialAuthService } from 'angularx-social-login';
3+
import {SocialAuthService, SocialUser} from 'angularx-social-login';
44
import { CookieService } from 'ngx-cookie-service';
55
import { of } from 'rxjs';
66

@@ -13,6 +13,9 @@ describe('LoginService', () => {
1313
let socialAuthService: SocialAuthService;
1414
let account;
1515
const socialAuthServiceStub = jasmine.createSpyObj('SocialAuthService', ['signOut', 'signIn']);
16+
socialAuthServiceStub.signIn.and.returnValue(new Promise<SocialUser>( resolve => {
17+
return {photoUrl: ''};
18+
}));
1619
const cookieStoreStub = {};
1720

1821
beforeEach(() => {

src/app/modules/login/services/login.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export class LoginService {
2020
}
2121

2222
signIn() {
23-
this.socialAuthService.signIn(GoogleLoginProvider.PROVIDER_ID);
23+
this.socialAuthService.signIn(GoogleLoginProvider.PROVIDER_ID).then(user => {
24+
localStorage.setItem('googleUserPhoto', user.photoUrl);
25+
});
2426
}
2527
logout() {
2628
this.socialAuthService.signOut();

src/app/modules/shared/components/user/user.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class=" py-8 flex items-center pl-3">
2-
<img src="{{ userPhoto }}" alt="user-icon" class="round"/>
2+
<img [src]="userPhoto" alt="user-icon" class="round"/>
33
<span class="pl-1">
44
<h2 class="font-poppins text-base font-semibold pl-2 dark:text-whiteTW">{{ userName }}</h2>
55
<p class="font-poppins mt-1 text-xs font-medium pl-2 text-grayTW dark:text-whiteTW">{{ userEmail }}</p>

src/app/modules/shared/components/user/user.component.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@ import { Component, OnInit } from '@angular/core';
22
import { environment } from 'src/environments/environment';
33
import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service';
44
import { LoginService } from '../../../login/services/login.service';
5-
import { SocialUser, SocialAuthService } from 'angularx-social-login';
65

76
@Component({
87
selector: 'app-user',
98
templateUrl: './user.component.html',
109
styleUrls: ['./user.component.scss'],
1110
})
1211
export class UserComponent implements OnInit {
13-
user: SocialUser;
1412
userPhoto: string;
1513
userName: string;
1614
userEmail: string;
1715
isProduction = environment.production;
1816

1917
constructor(
2018
private azureAdB2CService: AzureAdB2CService,
21-
private loginService: LoginService,
22-
private authService: SocialAuthService,
19+
private loginService: LoginService
2320
) { }
2421

2522
ngOnInit(): void {
@@ -36,11 +33,6 @@ export class UserComponent implements OnInit {
3633
this.azureAdB2CService.setTenantId();
3734
}
3835
}
39-
this.authService.authState.subscribe((user) => {
40-
this.user = user;
41-
this.userPhoto = user.photoUrl;
42-
localStorage.setItem('googleUserPhoto', this.userPhoto);
43-
});
4436
this.userPhoto = localStorage.getItem('googleUserPhoto');
4537
}
4638
}

0 commit comments

Comments
 (0)