8 changed files with 70 additions and 1 deletions
@ -1,9 +1,11 @@ |
|||
import { Routes } from '@angular/router'; |
|||
import { LoginComponent } from './login/login.component'; |
|||
import { RegisterComponent } from './register/register.component'; |
|||
import { GoogleCallbackComponent } from './google-callback/google-callback.component'; |
|||
|
|||
export const routes: Routes = [ |
|||
{ path: 'login', component: LoginComponent }, |
|||
{ path: 'register', component: RegisterComponent }, |
|||
{ path: 'google-callback', component: GoogleCallbackComponent }, |
|||
// Add other routes here
|
|||
]; |
|||
|
|||
@ -0,0 +1 @@ |
|||
<p>google-callback works!</p> |
|||
@ -0,0 +1,23 @@ |
|||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
|||
|
|||
import { GoogleCallbackComponent } from './google-callback.component'; |
|||
|
|||
describe('GoogleCallbackComponent', () => { |
|||
let component: GoogleCallbackComponent; |
|||
let fixture: ComponentFixture<GoogleCallbackComponent>; |
|||
|
|||
beforeEach(async () => { |
|||
await TestBed.configureTestingModule({ |
|||
imports: [GoogleCallbackComponent] |
|||
}) |
|||
.compileComponents(); |
|||
|
|||
fixture = TestBed.createComponent(GoogleCallbackComponent); |
|||
component = fixture.componentInstance; |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should create', () => { |
|||
expect(component).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,30 @@ |
|||
// src/app/google-callback/google-callback.component.ts
|
|||
import { Component, OnInit } from '@angular/core'; |
|||
import { AuthService } from '../auth.service'; |
|||
import { Router, ActivatedRoute } from '@angular/router'; |
|||
|
|||
@Component({ |
|||
selector: 'app-google-callback', |
|||
template: '<p>Loading...</p>', |
|||
styles: [] |
|||
}) |
|||
export class GoogleCallbackComponent implements OnInit { |
|||
constructor( |
|||
private authService: AuthService, |
|||
private router: Router, |
|||
private route: ActivatedRoute |
|||
) {} |
|||
|
|||
ngOnInit(): void { |
|||
this.route.queryParams.subscribe(params => { |
|||
console.log("callback-hit"); |
|||
const token = params['token']; |
|||
if (token) { |
|||
localStorage.setItem('token', token); |
|||
this.router.navigate(['/']); |
|||
} else { |
|||
this.router.navigate(['/login']); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue