npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular2-devise-token-auth

v1.2.1

Published

Helper library for working with Devise Token Auth in your Angular 2 applications

Downloads

14

Readme

angular2-devise-token-auth

Build Status npm version Commitizen friendly license

angular2-devise-token-auth is a helper library for working with Devise Token Auth in your Angular 2 applications.

Installation

npm install angular2-devise-token-auth --save

The library comes with some helpers that are useful in your Angular 2 apps.

  1. AuthHttp - allows for individual and explicit authenticated HTTP requests
  2. AuthService - provide the following features according the api:
    • sign in
    • sign up
    • sign out
    • validate token

How it works

After you did the sign in all requests will be authorized through the headers that will be sent automatically each request. You don't need to worry about it :sunglasses:.

Setup

It's supposed that you used Angular CLI to create your app.

  1. Include Auth library in the vendor files

    Open angular-cli-build.js.

    Include the library in the vendorNpmFiles array:

    var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
       
    module.exports = function(defaults) {
      return new Angular2App(defaults, {
        vendorNpmFiles: [
          ...
          'angular2-devise-token-auth/**/*.+(js|js.map)',
        ]
      });
    };
  2. System.js

    Open /src/system-config.ts. Modify the file like below:

    /** Map relative paths to URLs. */
    const map:any = {
      'angular2-devise-token-auth': 'vendor/angular2-devise-token-auth/dist'
    };
       
    /** User packages configuration. */
    const packages: any = {
      'angular2-devise-token-auth': {
        main: 'angular2-devise-token-auth.js'
      }
    };
  3. Bootstrap: The AuthService need to know where the auth endpoint is. So you need to pass it as an argument. So open /src/main.ts, inject the Auth providers, and specify your default endpoint:

    import {AUTH_PROVIDERS, authService} from 'angular2-devise-token-auth';
       
    class App {
      constructor() {}
    }
       
    bootstrap(App, [
      AUTH_PROVIDERS,
      authService('http://url-to-auth-endpoint')
    ])

How to use

AuthHttp

import {AuthHttp} from 'angular2-devise-token-auth';

@Injectable()
export class SomeService {
  thing: string;

  constructor(private authHttp: AuthHttp) {}

  getThing() {
    return this.authHttp.get('http://example.com/api/thing');
  }
}

AuthService

import {AuthService} from 'angular2-devise-token-auth';

@Component({ ... })
export class SomeComponent {

  constructor(private authService: AuthService) {
  }

  doIt() {
    this.authService.signUp({
      email: '[email protected]',
      password: '123456',
      password_confirmation: '123456',
    }).subscribe(res => console.log('LoL', res));
  }
}

Running unit tests

npm test

How to contribute :heart_eyes:

Follow the GitHub Flow

Pull Requests always will be welcome :metal: