1.0.7 • Published 4 years ago

@appstrax/ng-auth v1.0.7

Weekly downloads
66
License
SEE LICENSE IN LI...
Repository
github
Last release
4 years ago

@appstrax/ng-auth

This library contains a simple service, which allows you to easily integrate authentication into your applications.

Getting Started

Create your AppStrax Application (API Key) here: https://appstrax.tech.

You can use this test API Key: xdeWnV8XeYPVbki4Kcm2pBVjKUwHoYNZkuzL0ju8 (not recommended for production).

Installation

npm install @appstrax/ng-auth --save

Setup

In your app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

// Import the NgAuthModule
import { NgAuthModule } from '@appstrax/ng-auth';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    // Configure it with your Application ID
    NgAuthModule.forRoot({
      apiKey: "YOUR-API-KEY"
    })

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

In your component, inject the NgAuthService:

export class Component {

  constructor(
    // Other injectables...

    // Inject the NgAuthService
    private ngAuth: NgAuthService

  ) {}

}

Registration

export class AppComponent {
  public registrationRequest: RegistrationRequest = {
    firstname: "",
    lastname: "",
    email: "",
    password: ""
  };
  public registrationResponse: RegistrationResponse = {
    token: "",
    refreshToken
  };

  constructor(private ngAuth: NgAuthService) {}

  async register() {
    try {
      this.registrationResponse = await this.ngAuth.register(
        this.registrationRequest
      );

      // The JWT Token
      console.log(this.registrationResponse);
    } catch (err) {
      // The HTTP Error Response
    }
  }
}

Login

export class AppComponent {
  public authRequest: AuthRequest = {
    email: "",
    password: ""
  };
  public authResponse: AuthResponse = {
    token: ""
  };

  constructor(private ngAuth: NgAuthService) {}

  async login() {
    try {
      this.authResponse = await this.ngAuth.login(this.authRequest);

      // The JWT token
      console.log(this.authResponse);
    } catch (err) {
      // The HTTP Error Response
    }
  }
}

Development and Testing

You can run tests in the package by running ng test in the ./projects/ng-auth folder.

Publishing

npm run package
npm publish ./dist/ng-auth/appstrax-ng-auth-1.0.7.tgz
1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago