Skip to content

Commit 5cc7b61

Browse files
committed
refactor: delete azure login and create a base logic to login auth
1 parent 99a9ecb commit 5cc7b61

File tree

11 files changed

+20
-699
lines changed

11 files changed

+20
-699
lines changed

.dev.env

-36 Bytes
Binary file not shown.

src/app/modules/home/home.component.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/app/modules/home/home.component.scss

Whitespace-only changes.

src/app/modules/home/home.component.spec.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/app/modules/home/home.component.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Component, OnInit, NgZone } from '@angular/core';
2-
import { AzureAdB2CService } from './services/azure.ad.b2c.service';
32
import { Router } from '@angular/router';
43
import { FeatureToggleCookiesService } from '../shared/feature-toggles/feature-toggle-cookies/feature-toggle-cookies.service';
54

@@ -20,87 +19,20 @@ declare global {
2019
styleUrls: ['./login.component.scss'],
2120
})
2221
export class LoginComponent implements OnInit {
23-
isProduction = environment.production === EnvironmentType.TT_PROD_LEGACY;
2422
cliendId = CLIENT_URL;
2523
auth2: any;
2624

2725

2826
constructor(
29-
private azureAdB2CService: AzureAdB2CService,
3027
private router: Router,
3128
private featureToggleCookiesService: FeatureToggleCookiesService,
3229
private loginService?: LoginService,
3330
private userService?: UserService,
3431
private ngZone?: NgZone
3532
) {}
3633

37-
38-
googleAuthSDK() {
39-
const sdkLoaded = 'googleSDKLoaded';
40-
const gapi = 'gapi';
41-
42-
(window as any)[sdkLoaded] = () => {
43-
(window as any)[gapi].load('auth2', () => {
44-
this.auth2 = ( window as any)[gapi].auth2.init({
45-
client_id: this.cliendId,
46-
plugin_name: 'login',
47-
cookiepolicy: 'single_host_origin',
48-
scope: 'profile email'
49-
});
50-
});
51-
};
52-
53-
(async (d, s, id) => {
54-
const keyGoogle = 'src';
55-
const gjs = d.getElementsByTagName(s)[1];
56-
let js = gjs;
57-
if (d.getElementById(id)) { return; }
58-
js = d.createElement(s); js.id = id;
59-
js[keyGoogle] = 'https://accounts.google.com/gsi/client';
60-
gjs.parentNode.insertBefore(js, gjs);
61-
})(document, 'script', 'async defer');
62-
}
63-
6434
ngOnInit() {
65-
66-
this.googleAuthSDK();
67-
this.loginService.isLogin().subscribe(isLogin => {
68-
if (isLogin) {
69-
this.router.navigate(['']);
70-
}
71-
});
72-
73-
window.handleCredentialResponse = (response) => {
74-
const {credential = ''} = response;
75-
this.featureToggleCookiesService.setCookies();
76-
this.loginService.setLocalStorage('idToken', credential);
77-
this.loginService.getUser(credential).subscribe((resp) => {
78-
this.loginService.setCookies();
79-
const tokenObject = JSON.stringify(resp);
80-
const tokenJson = JSON.parse(tokenObject);
81-
this.loginService.setLocalStorage('user', tokenJson.token);
82-
this.ngZone.run(() => this.router.navigate(['']));
83-
});
84-
};
85-
}
86-
87-
login(): void {
88-
if (this.azureAdB2CService.isLogin()) {
89-
this.router.navigate(['']);
90-
} else {
91-
this.azureAdB2CService.signIn().subscribe(() => {
92-
this.featureToggleCookiesService.setCookies();
93-
this.azureAdB2CService.setCookies();
94-
const userId = this.azureAdB2CService.getUserId();
95-
this.userService.loadUser(userId).subscribe((user) => {
96-
const userGroups = {
97-
groups: user.groups
98-
};
99-
this.loginService.setLocalStorage('user', JSON.stringify(userGroups));
100-
this.router.navigate(['']);
101-
});
102-
});
103-
}
35+
this.loginService.fetchAndCheckUserPermissions();
10436
}
10537

10638
}

src/app/modules/login/services/azure.ad.b2c.service.spec.ts

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)