diff --git a/src/app/pages/login-social/login-social.component.ts b/src/app/pages/login-social/login-social.component.ts index c7cac491..7b43418e 100644 --- a/src/app/pages/login-social/login-social.component.ts +++ b/src/app/pages/login-social/login-social.component.ts @@ -27,28 +27,25 @@ declare global { } } - @Component({ selector: 'app-login-social', templateUrl: './login-social.component.html', - styleUrls: ['./login-social.component.css'] + styleUrls: ['./login-social.component.css'], }) export class LoginSocialComponent implements OnInit { private user: SocialUser | null = null; private loggedIn: boolean = false; - constructor( private authService: SocialAuthService, private http: HttpClient, private router: Router, private Service: AuthService - ) { } - - + ) {} ngOnInit(): void { - window['handleCredentialResponse'] = this.handleCredentialResponse.bind(this); + window['handleCredentialResponse'] = + this.handleCredentialResponse.bind(this); this.loadGoogleButton(); } @@ -65,18 +62,16 @@ export class LoginSocialComponent implements OnInit { const payload = jwt.split('.')[1]; const decodedPayload = atob(payload); const userInformation = JSON.parse(decodedPayload); - + const user: SocialUser = new SocialUser(); user.name = userInformation.name; user.email = userInformation.email; - + this.sendUserDataToServer(user); } - signInWithFB(): void { this.authService.signIn(FacebookLoginProvider.PROVIDER_ID).then((user) => { - if (user) { this.sendUserDataToServer(user); } @@ -90,16 +85,16 @@ export class LoginSocialComponent implements OnInit { private sendUserDataToServer(user: SocialUser) { const userSocialData = { name: user.name, - email: user.email + email: user.email, }; - + this.Service.loginSocialUser(userSocialData).subscribe( (response) => { console.log('Resposta do servidor:', response); - - if (response && response.access_token) { + + if (response && response.access_token) { localStorage.setItem('token', response.access_token); - + if (response.is_new_user) { this.router.navigate([`/editUser/${response.user_id}`]); } else { diff --git a/src/app/pages/login/login.component.spec.ts b/src/app/pages/login/login.component.spec.ts index aaa6ee93..07974c6c 100644 --- a/src/app/pages/login/login.component.spec.ts +++ b/src/app/pages/login/login.component.spec.ts @@ -14,7 +14,8 @@ import { CheckCodeRestPasswordComponent } from '../check-code-rest-password/chec import { RegisterComponent } from '../register/register.component'; import { of, throwError } from 'rxjs'; import { AlertService } from '../../services/alert.service'; -import { VideoComponent } from '../video/video.component'; +import { CatalogComponent } from '../catalog/catalog.component'; + import { HttpErrorResponse } from '@angular/common/http'; import { ActiveAccountComponent } from '../active-account/active-account.component'; @@ -60,7 +61,7 @@ describe('LoginComponent', () => { component: CheckCodeRestPasswordComponent, }, { path: 'register', component: RegisterComponent }, - { path: 'videos', component: VideoComponent }, + { path: 'catalog', component: CatalogComponent }, { path: 'activeAccount', component: ActiveAccountComponent }, ]), ], @@ -142,7 +143,8 @@ describe('LoginComponent', () => { it('should call navigator method when "Login com redes sociais" is clicked', () => { const navigatorSpy = spyOn(component, 'navigator').and.callThrough(); - const loginSocial = fixture.nativeElement.querySelector('#loginSocialButton'); + const loginSocial = + fixture.nativeElement.querySelector('#loginSocialButton'); loginSocial.click(); expect(navigatorSpy).toHaveBeenCalledWith('/loginsocial');