@nebular/auth
Version:
@nebular/auth
149 lines (148 loc) • 5.35 kB
TypeScript
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { NbAuthResult } from '../../services/auth-result';
import { NbAuthStrategy } from '../auth-strategy';
import { NbAuthStrategyClass } from '../../auth.options';
import { NbPasswordAuthStrategyOptions } from './password-strategy-options';
import * as i0 from "@angular/core";
/**
* The most common authentication provider for email/password strategy.
*
* Strategy settings. Note, there is no need to copy over the whole object to change the settings you need.
* Also, this.getOption call won't work outside of the default options declaration
* (which is inside of the `NbPasswordAuthStrategy` class), so you have to replace it with a custom helper function
* if you need it.
*
* ```ts
*export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
* name: string;
* baseEndpoint? = '/api/auth/';
* login?: boolean | NbPasswordStrategyModule = {
* alwaysFail: false,
* endpoint: 'login',
* method: 'post',
* requireValidToken: true,
* redirect: {
* success: '/',
* failure: null,
* },
* defaultErrors: ['Login/Email combination is not correct, please try again.'],
* defaultMessages: ['You have been successfully logged in.'],
* };
* register?: boolean | NbPasswordStrategyModule = {
* alwaysFail: false,
* endpoint: 'register',
* method: 'post',
* requireValidToken: true,
* redirect: {
* success: '/',
* failure: null,
* },
* defaultErrors: ['Something went wrong, please try again.'],
* defaultMessages: ['You have been successfully registered.'],
* };
* requestPass?: boolean | NbPasswordStrategyModule = {
* endpoint: 'request-pass',
* method: 'post',
* redirect: {
* success: '/',
* failure: null,
* },
* defaultErrors: ['Something went wrong, please try again.'],
* defaultMessages: ['Reset password instructions have been sent to your email.'],
* };
* resetPass?: boolean | NbPasswordStrategyReset = {
* endpoint: 'reset-pass',
* method: 'put',
* redirect: {
* success: '/',
* failure: null,
* },
* resetPasswordTokenKey: 'reset_password_token',
* defaultErrors: ['Something went wrong, please try again.'],
* defaultMessages: ['Your password has been successfully changed.'],
* };
* logout?: boolean | NbPasswordStrategyReset = {
* alwaysFail: false,
* endpoint: 'logout',
* method: 'delete',
* redirect: {
* success: '/',
* failure: null,
* },
* defaultErrors: ['Something went wrong, please try again.'],
* defaultMessages: ['You have been successfully logged out.'],
* };
* refreshToken?: boolean | NbPasswordStrategyModule = {
* endpoint: 'refresh-token',
* method: 'post',
* requireValidToken: true,
* redirect: {
* success: null,
* failure: null,
* },
* defaultErrors: ['Something went wrong, please try again.'],
* defaultMessages: ['Your token has been successfully refreshed.'],
* };
* token?: NbPasswordStrategyToken = {
* class: NbAuthSimpleToken,
* key: 'data.token',
* getter: (module: string, res: HttpResponse<Object>, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
* res.body,
* options.token.key,
* ),
* };
* errors?: NbPasswordStrategyMessage = {
* key: 'data.errors',
* getter: (module: string, res: HttpErrorResponse, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
* res.error,
* options.errors.key,
* options[module].defaultErrors,
* ),
* };
* messages?: NbPasswordStrategyMessage = {
* key: 'data.messages',
* getter: (module: string, res: HttpResponse<Object>, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
* res.body,
* options.messages.key,
* options[module].defaultMessages,
* ),
* };
* validation?: {
* password?: {
* required?: boolean;
* minLength?: number | null;
* maxLength?: number | null;
* regexp?: string | null;
* };
* email?: {
* required?: boolean;
* regexp?: string | null;
* };
* fullName?: {
* required?: boolean;
* minLength?: number | null;
* maxLength?: number | null;
* regexp?: string | null;
* };
* };
*}
* ```
*/
export declare class NbPasswordAuthStrategy extends NbAuthStrategy {
protected http: HttpClient;
private route;
protected defaultOptions: NbPasswordAuthStrategyOptions;
static setup(options: NbPasswordAuthStrategyOptions): [NbAuthStrategyClass, NbPasswordAuthStrategyOptions];
constructor(http: HttpClient, route: ActivatedRoute);
authenticate(data?: any): Observable<NbAuthResult>;
register(data?: any): Observable<NbAuthResult>;
requestPassword(data?: any): Observable<NbAuthResult>;
resetPassword(data?: any): Observable<NbAuthResult>;
logout(): Observable<NbAuthResult>;
refreshToken(data?: any): Observable<NbAuthResult>;
protected handleResponseError(res: any, module: string): Observable<NbAuthResult>;
static ɵfac: i0.ɵɵFactoryDeclaration<NbPasswordAuthStrategy, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<NbPasswordAuthStrategy>;
}