packages/data/src/lib/auth/login/login.component.ts
Uses LoginFormComponent. Tries to login via AuthService. Shows notifications and nexts success Subject if login was successful.
selector | ec-login |
templateUrl | login.component.html |
Properties |
|
Methods |
Inputs |
Outputs |
constructor(auth: AuthService, notificationService: NotificationsService, symbol: SymbolService)
|
||||||||||||
Parameters :
|
api | |
Type : PublicAPI
|
|
You can optionally specify PublicAPI instance. Defaults to SdkService#api. |
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). |
login | |||
login(undefined)
|
|||
Communicates with the AuthService. Handles loader, notifications and success Subject.
Parameters :
Returns :
void
|
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>