Skip to content

Latest commit

 

History

History
91 lines (59 loc) · 1.95 KB

README.md

File metadata and controls

91 lines (59 loc) · 1.95 KB

@nowzoo/ngx-sign-in-redirect

A service and component for displaying app messages.

Demo | Demo Source Code

Documentation

Quick start

npm i @nowzoo/ngx-sign-in-redirect save

Import the module...

import { NgxSignInRedirectModule } from '@nowzoo/ngx-sign-in-redirect';
@NgModule({
  imports: [
    NgxSignInRedirectModule.forRoot()
  ],
})
export class AppModule { }

Use the service in your components...

import { NgxSignInRedirectService } from '@nowzoo/ngx-sign-in-redirect';

export class MyGatedComponent implements OnInit {

  constructor(
    private svc: NgxSignInRedirectService,
    private auth: SomeAuthService,
    private router: Router
  ) { }

  ngOnInit() {
    if (! this.auth.signedIn) {
      this.svc.redirect = '/my/gated/path';
      this.router.navigate(['/sign-in']);
    }
  }

}

export class MySignInComponent implements OnInit {

  constructor(
    private svc: NgxSignInRedirectService,
    private auth: SomeAuthService,
  ) { }

  signIn(creds: any) {
    this.auth.signIn(creds)
      .then(() => {
        this.svc.redirectOnSignIn();
      })
  }

}

Contributing

This project was generated with Angular CLI version 7.1.4.

git clone https://github.com/nowzoo/ngx-sign-in-redirect.git

The library code is in projects/ngx-sign-in-redirect.

The demo is in projects/ngx-sign-in-redirect-demo

Build the library: ng build ngx-sign-in-redirect

Serve the demo locally: ng serve ngx-sign-in-redirect-demo

Unit tests

Run ng test ngx-sign-in-redirect to execute the unit tests via Karma.

The library tests can also be run with Wallaby. Select the wallaby.js file in projects/ngx-sign-in-redirect;