18.0.0 • Published 10 months ago

@bruno-bombonate/ngx-authentication v18.0.0

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

@bruno-bombonate/ngx-authentication

A package with AuthenticationService, that you can set, get and unset authentication in Angular apps.

Installation

npm install @bruno-bombonate/ngx-authentication

Compatibility table

@bruno-bombonate/ngx-authenticationAngular
1.0.015.x
2.0.016.x
3.0.017.x
18.0.018.x

Usage

sign-in.component.ts

import { Component, inject } from '@angular/core';
import { DestroyRefClass } from '@bruno-bombonate/ngx-classes';
import { HttpClient } from '@angular/common/http';
import { AuthenticationService } from '@bruno-bombonate/ngx-authentication';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
  selector: 'app-sign-in',
  templateUrl: './sign-in.component.html',
  styleUrls: ['./sign-in.component.sass']
})
export class SignInComponent extends DestroyRefClass {

  private readonly httpClient = inject(HttpClient);
  private readonly authenticationService = inject(AuthenticationService);

  public formLoading: boolean = false;

  public handleFormSubmit(value: any): void {
    if (this.formLoading === false) {
      this.formLoading = true;
      this.httpClient.post('users/sign-in')
        .pipe(takeUntilDestroyed(this.destroyRef))
        .subscribe({
          next: (response: any) => {
            this.authenticationService.setAuthentication(response.data, value.rememberMe);
          },
          error: (response: any) => {
            this.formLoading = false;
          }
        });
    }
  }

}

my-account.component.ts

import { Component } from '@angular/core';
import { AuthenticationService } from '@bruno-bombonate/ngx-authentication';

@Component({
  selector: 'app-my-account',
  templateUrl: './my-account.component.html',
  styleUrls: ['./my-account.component.sass']
})
export class MyAccountComponent {

  private readonly authenticationService = inject(AuthenticationService);

  public signOut(): void {
    this.authenticationService.unsetAuthentication();
  }

}
18.0.0

10 months ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.0

3 years ago