@nwx/jwt
A simple JWT module for Angular applications
![download-image](https://img.shields.io/npm/dm/@nwx/jwt.svg)
How to install
npm i @nwx/jwt |OR| yarn add @nwx/jwt
How to use
import { AppCfg, TargetPlatform } from '@nwx/cfg';
import { LogLevels } from '@nwx/logger';
export const environment: AppCfg = {
appName: '@nwx/jwt',
target: TargetPlatform.web,
production: false,
log: {
level: LogLevels.debug
},
jwt: {
networkDelay: 1,
expiryLeeway: 5
}
};
import { CfgModule } from '@nwx/cfg';
import { LoggerModule } from '@nwx/logger';
import { JwtModule } from '@nwx/jwt';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
CfgModule.forRoot(environment),
LoggerModule,
JwtModule
],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Component } from '@angular/core';
import { CfgService, DefaultCfg } from '@nwx/cfg';
import { LogService } from '@nwx/logger';
import { jwtService } from '@nwx/jwt';
@Component({
selector: 'app-root',
template: `<h1>Welcome to {{ title }}!</h1>`
})
export class AppComponent {
title = 'Neekware';
options = {};
constructor(public cfg: CfgService, public log: LogService, public jwt: JwtService) {
this.title = this.cfg.options.appName;
this.log.info('AppComponent loaded ...');
const someToken = 'some-jwt-token-received-from-server';
const payload = this.jwt.getPayload(someToken);
const isExpired = this.jwt.isExpired(payload);
if (!isExpired) {
const userId = payload.sub;
const nextRefresh = this.jwt.getRefreshTime(payload);
setTimeout(() => {
}, nextRefresh * 1000);
}
}
}
Running the tests
To run the tests against the current environment:
npm run ci:all
License
Released under a (MIT) license.
Version
X.Y.Z Version
`MAJOR` version -- making incompatible API changes
`MINOR` version -- adding functionality in a backwards-compatible manner
`PATCH` version -- making backwards-compatible bug fixes