update: google oauth2.0 with hd=email@forth.co.th only now functional

This commit is contained in:
Kenta420-Poom 2023-09-20 09:57:47 +07:00
parent 984707c7bf
commit 36c71eda38
31 changed files with 580 additions and 317 deletions

View file

@ -1,13 +1,19 @@
import { NgModule, inject } from '@angular/core';
import { CanActivateFn, Router, RouterModule, Routes } from '@angular/router';
import { UserService } from './core/services/user.service';
import { map } from 'rxjs';
import { Subject, finalize, lastValueFrom, map, takeUntil } from 'rxjs';
const authGuard: CanActivateFn = () => {
const userService: UserService = inject(UserService);
const router: Router = inject(Router);
return userService.isAuthenticated.pipe(
map((isAuth) => isAuth || router.parseUrl('/login'))
map((isAuth) => {
if (isAuth) {
return true;
}
return router.parseUrl('/login');
})
);
};
@ -15,14 +21,16 @@ const loginGuard: CanActivateFn = () => {
const userService: UserService = inject(UserService);
const router: Router = inject(Router);
return userService.isAuthenticated.pipe(
map((isAuth) => {
if (!isAuth) {
return true;
return lastValueFrom(userService.getCurrentUser())
.then(({ user }) => {
if (user) {
return router.parseUrl('/dashboard');
}
return router.parseUrl('/dashboard');
return true;
})
);
.catch(() => {
return true;
});
};
const routes: Routes = [
@ -33,10 +41,11 @@ const routes: Routes = [
canActivate: [loginGuard],
},
{
path: 'register',
path: 'callback',
loadComponent: () =>
import('./core/auth/auth.component').then((m) => m.AuthComponent),
canActivate: [loginGuard],
import('./core/callback/callback.component').then(
(m) => m.CallbackComponent
),
},
{
path: '',
@ -59,9 +68,10 @@ const routes: Routes = [
],
},
{
path: 'log',
loadComponent: () => import('./features/changelog/changelog.component').then((m) => m.ChangelogComponent),
}
path: '**',
pathMatch: 'full',
redirectTo: 'dashboard',
},
];
@NgModule({