rtoken
TypeScript icon, indicating that this package has built-in type declarations

1.3.6-beta.5 • Public • Published

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},
    ...
  ]
  ...
)}

Package Sidebar

Install

npm i rtoken

Weekly Downloads

9

Version

1.3.6-beta.5

License

MIT

Unpacked Size

307 kB

Total Files

69

Last publish

Collaborators

  • jeff0002
  • k1ch
  • smlee