'leave the desired page when the page is reloaded Angular
I'm trying to make sure that when the page is reloaded, the same page remains, but the initial page (authentication) loads . I save refreshToken, but how do I use it while waiting for this. I have a token saved in cookies
auth-interseptor.ts
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return this.store.select(getToken).pipe(
exhaustMap((token: string) => {
if (token) {
const authReq = req.clone({
headers: req.headers.append('authorization', token)
});
return next.handle(authReq);
} else {
return next.handle(req);
}
}),
catchError((err: HttpErrorResponse) => {
if (err.status === 401) {
this.router.navigate([RouterAuthPath.AUTH]);
}
return EMPTY;
})
);
}
auth.guard.ts
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.store.select(isAuthenticated).pipe(
map((authenticate: boolean) => {
if (authenticate) {
return true;
} else {
this.router.navigate([RouterAuthPath.AUTH]);
return false;
}
}),
);
}
app.component.ts
public ngOnInit(): void {
this.authService.checkRefreshToken().pipe(
tap((user: IResponseAuthData ) => {
this.store.dispatch(loginSuccess({user, redirect: false}));
}),
catchError(() => {
this.router.navigate([RouterAuthPath.AUTH]);
return EMPTY;
}),
takeUntil(this.ngUnsubscribe$),
).subscribe();
}
Solution 1:[1]
Getting date alone from a datetime string is not possible in MongoDB since it always returns an ISO date with time. As a workaround we can convert the time HH:mm:ss to 00:00:00 either by applying String operations on the string attribute or by using Arithmetic operations on the date. We will have to add a temporary field in the query which will hold the converted value using add field operations. And then we can compare them with a given date.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Iqbal |
