Skip to content

Instantly share code, notes, and snippets.

@changhuixu
Created July 26, 2020 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save changhuixu/56e3d49398d92772da4b03bdfd7c73b9 to your computer and use it in GitHub Desktop.
Save changhuixu/56e3d49398d92772da4b03bdfd7c73b9 to your computer and use it in GitHub Desktop.
export function appInitializer(authService: AuthService) {
return () =>
new Promise((resolve) => {
console.log('refresh token on app start up')
authService.refreshToken().subscribe().add(resolve);
});
}
@Krzysztofz01
Copy link

This method won't work in Rxjs included in Angular 13. We can refactor the interceptor like this:

export function appInitializer(authService: AuthService) {
  return () =>
    new Promise((resolve) => {
      console.log('refresh token on app start up')
      return () => firstValueFrom(authService.refreshToken());
    });
}

Also don't use:

return authService.refreshToken().toPromise()

This method is depracated and will be removed soon.

@changhuixu
Copy link
Author

Hi @Krzysztofz01 , thank you for pointing it out.
I have updated the solution to Angular v13.
Please check my Git repo for details.

https://github.com/dotnet-labs/JwtAuthDemo/blob/51ef91c75bed8538c62700014c0ad828f63d486a/angular/src/app/core/services/app-initializer.ts#L4-L8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment