Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

neroniaky/angular-token

Repository files navigation

Token based authentication service for Angular with interceptor and multi-user support. Works best with the devise token auth gem for Rails.

This library has been renamed to Angular-Token! Please follow the migration guide.


Quick Links


Install

  1. Set up a Rails with Devise Token Auth

  2. Install Angular-Token via NPM with

    npm install angular-token
  3. Import and add AngularTokenModule to your main module and call the 'forRoot' function with the config. Make sure you have HttpClientModule imported too.

    import { AngularTokenModule } from 'angular-token';

    @NgModule({
    imports: [
    ...,
    HttpClientModule,
    AngularTokenModule.forRoot({
    ...
    })
    ],
    declarations: [ ... ],
    bootstrap: [ ... ]
    })
  4. (Maybe Optional) Fix injection context runtime error After installing this package, if you get an Error: inject() must be called from an injection context when running your app, add the following to your typescript path config in the tsconfig[.app].json file:

    "paths": {
    "@angular/*": [ "./node_modules/@angular/*" ]
    }

Use

  1. Register your user

    console.log(res), error => console.log(error) );">constructor(private tokenService: AngularTokenService) { }

    this.tokenService.registerAccount({
    login: 'example@example.org',
    password: 'secretPassword',
    passwordConfirmation: 'secretPassword'
    }).subscribe(
    res => console.log(res),
    error => console.log(error)
    );
  2. Sign in your user

    console.log(res), error => console.log(error) );">constructor(private tokenService: AngularTokenService) { }

    this.tokenService.signIn({
    login: 'example@example.org',
    password: 'secretPassword'
    }).subscribe(
    res => console.log(res),
    error => console.log(error)
    );
  3. Now you can use HttpClient to access private resources

    console.log(res), error => console.log(error) );">constructor(http: HttpClient) { }

    this.http.get('private_resource').subscribe(
    res => console.log(res),
    error => console.log(error)
    );

Contributors


Jan-Philipp Riethmacher

Arjen Brandenburgh

License

The MIT License (see the LICENSE file for the full text)

About

Token based authentication service for Angular with interceptor and multi-user support. Works best with devise token auth for Rails. Example:

Topics

Resources

Readme

License

MIT license

Stars

Watchers

Forks

Packages

Contributors