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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@oitmain/angularedux-auth

v0.0.11

Published

Angular Redux/Ngrx Auth Module // This package is still improving.

Readme

@oitmain/angularedux-auth

Angular Redux/Ngrx Auth Module // This package is still improving.

Installation - After install node package

To get started, tsconfig.json in your application

// tsconfig.json
 "lib": [
      "es2017",
      "dom"
    ]
  },
  "include": [
    "src/**/*",
    "node_modules/@oitmain/angularedux-auth/lib/index.ts"
  ]
  • Import AuthModule from your root module
import { AuthModule } from '@oitmain/angularedux-auth/lib'; 

and

imports: [
    ...
    AuthModule,
    ...
]

Descriptions

  • AuthService: Set Api service and address
  • AuthEffects: Interaction between server side & client side
  • AuthGuardService: Let only allowed-user can access specific page - You need to define 'canActive' feature in your routing module.

Sample Skeleton template (In your template)

  • How to import from reducer and define store in your container/component
/** For using Authentication */
import { Auth } from '@oitmain/angularedux-auth/lib';

/** For dispatching action to NGRX */
import { Store } from '@ngrx/store';
import * as rootReducer from '@oitmain/angularedux-auth/lib/reducers';
import * as authAction from '@oitmain/angularedux-auth/lib/actions/auth.action';

constructor( 
    // ...
    private store: Store<rootReducer.State>,
    private router: Router
) {}

ngOnInit() {
    this.userToken$ = this.store.select(rootReducer.getAuthUserToken);
    this.payload$ = this.store.select(rootReducer.getAuthPayload);

    /** Redirect to main application */
    this.isSignedIn_Subscription$ = (
        this.isSignedIn$ = this.store.select(rootReducer.getAuthIsSignedIn)).subscribe((val)=>{

        if(val) {
            this.router.navigate(['/app']);
        }
    });

    this.status_Subscription$ = (
        this.status$ = this.store.select(rootReducer.getAuthStatus)).subscribe((val)=>{

        if(val === 'Signin Success') {
            let signedUser: string;
            this.userToken$.subscribe((userToken)=>{
                signedUser = userToken;
            }).unsubscribe();

            /** For now, signedin keep alive for 25 hours  */
            localStorage.setItem('isExpiredAt',(Date.now() + 90000000).toString());
            localStorage.setItem('isSignedIn','true');
            localStorage.setItem('userToken',signedUser);
        }
    });

    if(localStorage.getItem('isSignedIn') === 'true') {
        if(parseInt(localStorage.getItem('isExpiredAt')) <= Date.now()) {
            localStorage.removeItem('isExpiredAt');
            localStorage.removeItem('isSignedIn');
            localStorage.removeItem('userToken');

            alert('Please Sign In Again!');
        } else {
            this.router.navigate(['/app']);
        }
    }
}

// ... Your code goes here

Usage & Documentations

1. State tree from authState

  • This module has Ngrx root state, so please use 'forFeature' for both Reducers & States

2. First step, authService to use API calls

  • To use API call, you need to set both a service and an uri
/**
 * Logically, this should be called before any other API calls
 */
// In your appropriate page container - Maybe in your constructor OR ngOnInit
import { AuthService } from '@oitmain/angularedux-auth/lib';

constructor(
        // ...
        private authService: AuthService
) {
    authService.setService({
        name: 'graphcool',
        uri: 'YOUR_URI_FOR_AUTH',
        uriName: 'auth',
        isTokenAhead: false
    });
}

3. Change State manually by using ResetAuthAction

  • Use ResetAuthAction when user's token still alive OR when you need to change previous state. For example, I need to change state from 'Signin Fail' to 'Move Another Page'
// In ngOnDestroy() because you are exiting from current page
this.store.dispatch(new authAction.ResetAuthAction({
    isSignedIn: new Boolean(localStorage.getItem('isSignedIn')).valueOf(),
    userToken: localStorage.getItem('userToken'),
    status: 'Move Another Page',
    payload: 'Reset Auth Action'
}));

4. AuthGuardService

  • You can use isSignedIn in AuthState when you need whether user signed in.
  • However, AuthGuardService handle both localStorage & AuthState, so please use the service when you need a guard for limited page in your router module.

For Debug purpose

  • Use @ngrx/store-devtools (You don't need to install this package - It's already in this package)
// In you module
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { environment } from '../environments/environment';
...
imports: [
    // ...
    !environment.production ? StoreDevtoolsModule.instrument({ maxAge: 50 }) : []
],

Updates

(Version 0.0.10~11)

  • Removed all successful status, use 'Token' directly.
  • Now status has following: You can use this in your components or views.

| value | string of status | |----------------|------------------------------| | INIT | 'auth-status-init' | | GET_TOKEN_FAIL | 'auth-status-get-token-fail' | | SIGNIN_FAIL | 'auth-status-signin-fail' | | SIGNUP_FAIL | 'auth-status-signup-fail' |

    <!-- In your html view -->
<auth-signin 
    [status]='status$ | async'
></auth-signin>
    <!-- ... -->
<div *ngIf="status === 'auth-status-signin-fail'">
    <!-- Your view action when signin fails -->
</div>

or

    // In your typescript component
import { AuthStatus } from '@oitmain/angularedux-auth/lib';
    // ...

(this.store.select(rootReducer.getAuthStatus)).subscribe((res)->{
    if(res === AuthStatus.SIGNIN_FAIL) {
        // Your action when signin fails
    }
});

(Version 0.0.9)

  • Improved signout: Once it signout, then all state and action is reset.
  • To use this, just call signout action.
this.store.dispatch(new authAction.SignOutAction);

(Version 0.0.8)

  • Now it's possible to use 'Get Token ahead Signin'
  • Flow: (Get Token) -> (Try to signin using your token name)
  • This action calls 2 Apis, and it is more flexible to use (using tokenName...etc)
this.store.dispatch(new authAction.GetTokenAheadSigninAction({
    apiForSignin: 'API_FOR_SIGNIN',
    apiForToken: 'API_FOR_GET_TOKEN',
    tokenName: 'YOUR_TOKEN_NAME',
    headers: {
        'Content-Type':'application/x-www-form-urlencoded',
        'Access-Control-Allow-Origin':'*'
    },
    params: {
        'username': id_from_view,
        'password': pwd_from_view
    }
}));
  • Important! This action doesn't call Signin Success, this calls either Signin Result or Signin Fail, so please call Signin Success in your module. (Of course, this action calls GetTokenFail action if some error happened as it creates a token)

References

  • @ngrx/store