- Notifications
You must be signed in to change notification settings - Fork182
🔑 Token based authentication service for Angular with interceptor and multi-user support. Works best with devise token auth for Rails. Example:
License
neroniaky/angular-token
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
🔑 Token based authentication service for Angular with interceptor and multi-user support. Works best with thedevise token auth gem for Rails.
👋 This library has been renamed toAngular-Token! Please follow themigration guide.
- 🚀 View to demo onStackblitz
- ✨ Learn about it on thedocs site
- 🔧 Support us bycontributing
Set up a Rails withDevise Token Auth
Install Angular-Token via NPM with
npm install angular-token
Import and add
AngularTokenModule
to your main module and call the 'forRoot' function with the config. Make sure you haveHttpClientModule
imported too.import{AngularTokenModule}from'angular-token';@NgModule({imports:[ ...,HttpClientModule,AngularTokenModule.forRoot({ ...})],declarations:[ ...],bootstrap:[ ...]})
(Maybe Optional) Fix injection context runtime errorAfter 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 thetsconfig[.app].json
file:"paths": {"@angular/*": ["./node_modules/@angular/*" ]}
Register your user
constructor(privatetokenService:AngularTokenService){}this.tokenService.registerAccount({login:'example@example.org',password:'secretPassword',passwordConfirmation:'secretPassword'}).subscribe(res=>console.log(res),error=>console.log(error));
Sign in your user
constructor(privatetokenService:AngularTokenService){}this.tokenService.signIn({login:'example@example.org',password:'secretPassword'}).subscribe(res=>console.log(res),error=>console.log(error));
Now you can use HttpClient to access private resources
constructor(http:HttpClient){}this.http.get('private_resource').subscribe(res=>console.log(res),error=>console.log(error));
Jan-Philipp Riethmacher | Arjen Brandenburgh |
---|
The MIT License (see theLICENSE 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
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.