File

packages/data/src/lib/auth/login/login.component.ts

Description

Uses LoginFormComponent. Tries to login via AuthService. Shows notifications and nexts success Subject if login was successful. https://components.entrecode.de/auth/auth?e=1

Implements

WithLoader WithNotifications

Metadata

selector ec-login
templateUrl login.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(auth: AuthService, notificationService: NotificationsService, symbol: SymbolService)
Parameters :
Name Type Optional
auth AuthService No
notificationService NotificationsService No
symbol SymbolService No

Inputs

api
Type : PublicAPI

You can optionally specify PublicAPI instance. Defaults to SdkService#api.

Outputs

error
Type : EventEmitter<AccountResource>

Subject that is nexted when an error occurs. For custom error reactions

success
Type : EventEmitter<AccountResource>

Subject that is nexted when the login was successful. Meant to be used for redirecting to another page (or similar).

Methods

login
login(undefined)

Communicates with the AuthService. Handles loader, notifications and success Subject.

Parameters :
Name Optional
No
Returns : void

Properties

Public auth
Type : AuthService
loader
Decorators :
@ViewChild(LoaderComponent, {static: true})

The included loader.

notifications
Type : Notification[]
Default value : []

Error notifications

Public notificationService
Type : NotificationsService
Public symbol
Type : SymbolService
import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import {
  LoaderComponent, Notification,

  NotificationsService, SymbolService,




  WithLoader, WithNotifications
} from '@ec.components/ui';
import PublicAPI from 'ec.sdk/lib/PublicAPI';
import AccountResource from 'ec.sdk/lib/resources/accounts/AccountResource';
import { AuthService } from '../auth.service';

/** Uses LoginFormComponent. Tries to login via AuthService. Shows notifications and nexts success Subject if login was successful.
 * <example-url>https://components.entrecode.de/auth/auth?e=1</example-url>
 */
@Component({
  selector: 'ec-login',
  templateUrl: 'login.component.html',
})
export class LoginComponent implements WithLoader, WithNotifications {
  /** You can optionally specify PublicAPI instance. Defaults to SdkService#api. */
  @Input() api: PublicAPI;
  /** Subject that is nexted when the login was successful. Meant to be used for redirecting to another page (or similar). */
  @Output() success: EventEmitter<AccountResource> = new EventEmitter();
  /** Subject that is nexted when an error occurs. For custom error reactions */
  @Output() error: EventEmitter<AccountResource> = new EventEmitter();
  /** The included loader. */
  @ViewChild(LoaderComponent, { static: true }) loader;
  /** Error notifications */
  notifications: Notification[] = [];

  constructor(
    public auth: AuthService,
    public notificationService: NotificationsService,
    public symbol: SymbolService,
  ) {}
  /** Communicates with the AuthService. Handles loader, notifications and success Subject. */
  login({ email, password }) {
    const login = this.auth
      .login({ email, password }, this.api)
      .then((user) => {
        this.notificationService.emit({
          type: 'success',
          title: this.symbol.resolve('login.success'),
          hide: this.notifications,
        });
        this.success.emit(user);
      })
      .catch((error) => {
        this.notificationService.emit({
          title: this.symbol.resolve('login.error'),
          error,
          sticky: true,
          hide: this.notifications,
          replace: this.notifications,
        });
        this.error.next(error);
        console.log('could not login', error);
      });
    this.loader.wait(login);
  }
}
<ec-loader class="ec-loader is-global"></ec-loader>
<ec-login-form (success)="login($event)"></ec-login-form>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""