rtoken
v1.3.6-beta.5
Published
Realster Token Module
Downloads
94
Readme
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 // determines if the cookie will be local or global
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', // needed for cross domain access if the backend is in a different domain or port
}),
],
providers: [
/**
* The order will determine the order of the interceptors
**/
{provide: HTTP_INTERCEPTORS, useClass: RTokenRequestInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: RTokenResponseInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: RTokenErrorInterceptor, multi: true},
...
]
...
)}