UNPKG

5.17 kBTypeScriptView Raw
1import { HttpClient } from '@angular/common/http';
2import { ActivatedRoute } from '@angular/router';
3import { Observable } from 'rxjs';
4import { NbAuthResult } from '../../services/auth-result';
5import { NbAuthStrategy } from '../auth-strategy';
6import { NbAuthStrategyClass } from '../../auth.options';
7import { NbPasswordAuthStrategyOptions } from './password-strategy-options';
8/**
9 * The most common authentication provider for email/password strategy.
10 *
11 * Strategy settings. Note, there is no need to copy over the whole object to change the settings you need.
12 * Also, this.getOption call won't work outside of the default options declaration
13 * (which is inside of the `NbPasswordAuthStrategy` class), so you have to replace it with a custom helper function
14 * if you need it.
15 *
16 * ```ts
17 *export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
18 * name: string;
19 * baseEndpoint? = '/api/auth/';
20 * login?: boolean | NbPasswordStrategyModule = {
21 * alwaysFail: false,
22 * endpoint: 'login',
23 * method: 'post',
24 * requireValidToken: true,
25 * redirect: {
26 * success: '/',
27 * failure: null,
28 * },
29 * defaultErrors: ['Login/Email combination is not correct, please try again.'],
30 * defaultMessages: ['You have been successfully logged in.'],
31 * };
32 * register?: boolean | NbPasswordStrategyModule = {
33 * alwaysFail: false,
34 * endpoint: 'register',
35 * method: 'post',
36 * requireValidToken: true,
37 * redirect: {
38 * success: '/',
39 * failure: null,
40 * },
41 * defaultErrors: ['Something went wrong, please try again.'],
42 * defaultMessages: ['You have been successfully registered.'],
43 * };
44 * requestPass?: boolean | NbPasswordStrategyModule = {
45 * endpoint: 'request-pass',
46 * method: 'post',
47 * redirect: {
48 * success: '/',
49 * failure: null,
50 * },
51 * defaultErrors: ['Something went wrong, please try again.'],
52 * defaultMessages: ['Reset password instructions have been sent to your email.'],
53 * };
54 * resetPass?: boolean | NbPasswordStrategyReset = {
55 * endpoint: 'reset-pass',
56 * method: 'put',
57 * redirect: {
58 * success: '/',
59 * failure: null,
60 * },
61 * resetPasswordTokenKey: 'reset_password_token',
62 * defaultErrors: ['Something went wrong, please try again.'],
63 * defaultMessages: ['Your password has been successfully changed.'],
64 * };
65 * logout?: boolean | NbPasswordStrategyReset = {
66 * alwaysFail: false,
67 * endpoint: 'logout',
68 * method: 'delete',
69 * redirect: {
70 * success: '/',
71 * failure: null,
72 * },
73 * defaultErrors: ['Something went wrong, please try again.'],
74 * defaultMessages: ['You have been successfully logged out.'],
75 * };
76 * refreshToken?: boolean | NbPasswordStrategyModule = {
77 * endpoint: 'refresh-token',
78 * method: 'post',
79 * requireValidToken: true,
80 * redirect: {
81 * success: null,
82 * failure: null,
83 * },
84 * defaultErrors: ['Something went wrong, please try again.'],
85 * defaultMessages: ['Your token has been successfully refreshed.'],
86 * };
87 * token?: NbPasswordStrategyToken = {
88 * class: NbAuthSimpleToken,
89 * key: 'data.token',
90 * getter: (module: string, res: HttpResponse<Object>, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
91 * res.body,
92 * options.token.key,
93 * ),
94 * };
95 * errors?: NbPasswordStrategyMessage = {
96 * key: 'data.errors',
97 * getter: (module: string, res: HttpErrorResponse, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
98 * res.error,
99 * options.errors.key,
100 * options[module].defaultErrors,
101 * ),
102 * };
103 * messages?: NbPasswordStrategyMessage = {
104 * key: 'data.messages',
105 * getter: (module: string, res: HttpResponse<Object>, options: NbPasswordAuthStrategyOptions) => getDeepFromObject(
106 * res.body,
107 * options.messages.key,
108 * options[module].defaultMessages,
109 * ),
110 * };
111 * validation?: {
112 * password?: {
113 * required?: boolean;
114 * minLength?: number | null;
115 * maxLength?: number | null;
116 * regexp?: string | null;
117 * };
118 * email?: {
119 * required?: boolean;
120 * regexp?: string | null;
121 * };
122 * fullName?: {
123 * required?: boolean;
124 * minLength?: number | null;
125 * maxLength?: number | null;
126 * regexp?: string | null;
127 * };
128 * };
129 *}
130 * ```
131 */
132export declare class NbPasswordAuthStrategy extends NbAuthStrategy {
133 protected http: HttpClient;
134 private route;
135 protected defaultOptions: NbPasswordAuthStrategyOptions;
136 static setup(options: NbPasswordAuthStrategyOptions): [NbAuthStrategyClass, NbPasswordAuthStrategyOptions];
137 constructor(http: HttpClient, route: ActivatedRoute);
138 authenticate(data?: any): Observable<NbAuthResult>;
139 register(data?: any): Observable<NbAuthResult>;
140 requestPassword(data?: any): Observable<NbAuthResult>;
141 resetPassword(data?: any): Observable<NbAuthResult>;
142 logout(): Observable<NbAuthResult>;
143 refreshToken(data?: any): Observable<NbAuthResult>;
144 protected handleResponseError(res: any, module: string): Observable<NbAuthResult>;
145}