rToken
token and cookie handling npm package
Installation
Install this package locally with npm.
npm install rtoken --save
Usage
/main.module.ts (app.module.ts)
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { environment } from '../environtments/environment';
...
import { RTokenInterceptorModule } from 'rtoken';
@NgModule({
...
imports: [
HttpClientModule,
RTokenInterceptorModule.initInterceptor({
production: environment.production
cookieName: 'domainCookieName',
loginURL: 'https://domain.com/login'
})
...
]
...
})
Where you make http method calls
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { RTokenRequestInterceptor, RTokenResponseInterceptor, RTokenErrorInterceptor } from 'rtoken';
@NgModule({
...
imports: [
BrowserModule,
HttpClientModule,
HttpClientXsrfModule.withOptions({
headerName: 'X-Access-Token',
}),
],
providers: [
{provide: HTTP_INTERCEPTORS, useClass: RTokenRequestInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: RTokenResponseInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: RTokenErrorInterceptor, multi: true},
...
]
...
)}