npm package: @ngsm/auth
Description: <p align="center">   <a href="https://github.com/ng-sm">     <img src="https://avatars2.githubusercontent.com/u/64587411?s=150">   </a> </p> <p align="center">   Angular JWT Authentication module </p>
Latest version: 0.1.0

<p align="center">
  <a href="https://github.com/ng-sm">
    <img src="https://avatars2.githubusercontent.com/u/64587411?s=150">
  </a>
</p>
<p align="center">
  Angular JWT Authentication module
</p>

## Installation

`yarn add @ngsm/auth` or `npm i @ngsm/auth --save`

## Usage

app.module.ts
```ts
import { AuthInterceptor, ErrorInterceptor } from '@ngsm/auth';

@NgModule({
  ...,
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
  ],
};
```

app-routing.module.ts
```ts
  import { AuthGuard, AuthGuestGuard } from '@ngsm/auth';

  ...
  {
    path: 'sign-in',
    canActivate: [AuthGuestGuard],
    loadChildren: () => import('./+sign-in/sign-in.module').then(m => m.SignInModule),
  }

  ...

  {
    path: 'homepage',
    canActivate: [AuthGuard],
    component: HoemapgeComponent,
  }
```

Example how to use auth service (based on @ngsm/query module):
```ts
import { AuthService } from '@ngsm/auth';

...
export class ExampleComponent implements ngOnInit {
  signInQuery$ = this.authFacade.signInQuery$;

  get user(): User {
    return this.authService.user;
  }

  constructor(
    private authService: AuthService,
    private authFacade: AuthFacade,
  ) {}

  ngOnInit() {
    this.login();
  }

  logout(): void {
    this.authService.logout();
  }

  login(): void {
    this.signInQuery$
      .pipe(filter(query => hasQuerySucceeded(query)))
      .subscribe(({ response }) => this.authService.loginSuccess(response));
  }
  
  ...
}
```

## Author

<table border="0">
  <tr>
    <td>
      <a href="https://github.com/sebastianmusial" style="color: white">
        <img src="https://github.com/sebastianmusial.png?s=150" width="150"/>
      </a>
    </td>
    <td>
      <p><strong>Sebastian Musiał</strong></p>
      <p><img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIF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VjLTAuMzA3LTAuNDYtMC4xODMtMS4wOCwwLjI3Ny0xLjM4N2w5LTZjMC40Ni0wLjMwNywxLjA4MS0wLjE4MywxLjM4NywwLjI3NyAgICAgYzAuMzA3LDAuNDYsMC4xODMsMS4wOC0wLjI3NywxLjM4N2wtOSw2QzYuMzg0LDMzLjk0NSw2LjE5MSwzNCw2LjAwMSwzNHoiLz48L2c+PGc+PHBhdGggZD0iTTQxLjk5OSwzNGMtMC4xOSwwLTAuMzgzLTAuMDU1LTAuNTU0LTAuMTY4bC05LTZjLTAuNDYtMC4zMDctMC41ODQtMC45MjctMC4yNzctMS4zODcgICAgIGMwLjMwNi0wLjQ2LDAuOTI2LTAuNTg0LDEuMzg3LTAuMjc3bDksNmMwLjQ2LDAuMzA3LDAuNTg0LDAuOTI3LDAuMjc3LDEuMzg3QzQyLjY0LDMzLjg0NCw0Mi4zMjIsMzQsNDEuOTk5LDM0eiIvPjwvZz48L2c+PC9nPjwvc3ZnPg==" style="width: 18px; height: 18px; vertical-align: middle; margin: 0 5px 5px 0"> <a href="mailto:kontakt@sebastianmusial.pl">kontakt@sebastianmusial.pl</a></p>
      <p><img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkJz48c3ZnIGhlaWdodD0iNTEycHgiIGlkPSLlvaLnirZfMl8xXyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNTEyIDUxMjsiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDUxMiA1MTIiIHdpZHRoPSI1MTJweCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0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