Created
September 10, 2024 10:06
-
-
Save OsirisTerje/cc87d5ebdda6e69c3432de41c4908889 to your computer and use it in GitHub Desktop.
Angular interceptor for redirecting to Fhi.HelseId login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { HttpErrorResponse, HttpEvent, HttpEventType, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HttpStatusCode } from '@angular/common/http'; | |
| import { Injectable } from '@angular/core'; | |
| import { Observable } from 'rxjs'; | |
| import { tap } from 'rxjs/operators'; | |
| @Injectable() | |
| export class AuthRedirectInterceptor implements HttpInterceptor { | |
| intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | |
| return next.handle(req).pipe(tap({ | |
| error: (err: any) => { | |
| if (err instanceof HttpErrorResponse) { | |
| if ((err.status == HttpStatusCode.Unauthorized)) { | |
| window.location.href = '/Account/Login'; | |
| } | |
| } | |
| } | |
| })); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment