Skip to content

Commit 3bee7e3

Browse files
feat: TT-577 get profile pic from Google account (#825)
* feat: TT-577 get profile pic from Google account * feat: TT-577 get profile pic from Google account * feat: TT-577 get profile pic from Google account Co-authored-by: alejandra-ponce <[email protected]>
1 parent 24d7f40 commit 3bee7e3

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
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();
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class=" py-8 flex items-center pl-3">
2-
<img src="assets/icons/user.svg" alt="user-icon" width="40" height="40"/>
2+
<img [src]="userPhoto" alt="user-icon" class="round"/>
33
<span class="pl-1">
4-
<h2 class="font-poppins text-base font-semibold pl-2 dark:text-whiteTW">{{userName}}</h2>
5-
<p class="font-poppins mt-1 text-xs font-medium pl-2 text-grayTW dark:text-whiteTW">{{userEmail}}</p>
4+
<h2 class="font-poppins text-base font-semibold pl-2 dark:text-whiteTW">{{ userName }}</h2>
5+
<p class="font-poppins mt-1 text-xs font-medium pl-2 text-grayTW dark:text-whiteTW">{{ userEmail }}</p>
66
</span>
7-
</div>
7+
</div>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@import '../../../../../styles/colors.scss';
22

3+
.round {
4+
width:40px;
5+
height:40px;
6+
border-radius:150px;
7+
}
8+
39
.user-profile {
410
color: black;
511
cursor: pointer;

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@ import { LoginService } from '../../../login/services/login.service';
99
styleUrls: ['./user.component.scss'],
1010
})
1111
export class UserComponent implements OnInit {
12+
userPhoto: string;
1213
userName: string;
1314
userEmail: string;
1415
isProduction = environment.production;
1516

16-
constructor(private azureAdB2CService: AzureAdB2CService, private loginService: LoginService) {}
17+
constructor(
18+
private azureAdB2CService: AzureAdB2CService,
19+
private loginService: LoginService
20+
) { }
1721

1822
ngOnInit(): void {
19-
if (this.isProduction){
23+
if (this.isProduction) {
2024
if (this.azureAdB2CService.isLogin()) {
2125
this.userName = this.azureAdB2CService.getName();
2226
this.userEmail = this.azureAdB2CService.getUserEmail();
2327
this.azureAdB2CService.setTenantId();
2428
}
25-
}else{
29+
} else {
2630
if (this.loginService.isLogin()) {
2731
this.userName = this.loginService.getName();
2832
this.userEmail = this.loginService.getUserEmail();
2933
this.azureAdB2CService.setTenantId();
3034
}
3135
}
36+
this.userPhoto = localStorage.getItem('googleUserPhoto');
3237
}
3338
}

0 commit comments

Comments
 (0)