Skip to content

Instantly share code, notes, and snippets.

@OsirisTerje
Created September 10, 2024 10:06
Show Gist options
  • Select an option

  • Save OsirisTerje/cc87d5ebdda6e69c3432de41c4908889 to your computer and use it in GitHub Desktop.

Select an option

Save OsirisTerje/cc87d5ebdda6e69c3432de41c4908889 to your computer and use it in GitHub Desktop.
Angular interceptor for redirecting to Fhi.HelseId login
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