npm i --save ns-angular-jwt
                    
                    - Version: 1.0.0
- GitHub: https://github.com/slejnej/ns-angular-jwt
- NPM: https://www.npmjs.com/package/ns-angular-jwt
- Downloads:
- Last Day: 0
- Last Week: 0
- Last Month: 0
Nativescript - Angular - JWT
- Angular v11+ and RxJS v6+ -> v1.0
The library provides an HttpInterceptor which automatically attaches a JSON Web Token to HttpClient requests.
Installation
# installation with tns
tns install slejnej/ns-angular-jwtUsage
- make sure you have credentials from your any OAuth2 service
- create your injectable AuthGuardservice in app root as follows
// file - auth-guard.service
import all_needed_used_and_injected!!!
@Injectable()
export class AuthGuard implements CanActivate {
    subscription: Subscription;
    
    constructor(private routerExtensions: RouterExtensions, protected authService: AuthService,
        protected userService: UserService, private storage: SecureStorageService) { }
    
    canActivate() {
        if (this.authService.isAuthenticated()) {
            console.log('guard OK');
            return true;
        }
        else {
            console.log('guard FAIL');
            // logout user and redirect
            return false;
        }
    }
    - in your app-routing.module.tscheck that you have defined auth providers as:
import { AuthGuard } from "~/auth-guard.service";
export const authProviders = [
  AuthGuard
];- create new token.interceptor.ts