@rqdhw3n/react-auth-flow 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +371 -173
- package/dist/index.cjs.js +779 -210
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +126 -65
- package/dist/index.es.js +744 -175
- package/dist/index.es.js.map +1 -1
- package/dist/style.css +209 -47
- package/package.json +24 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { Context } from 'react';
|
|
2
2
|
import { default as default_2 } from 'react';
|
|
3
3
|
|
|
4
|
+
export declare interface AuthActionResponse {
|
|
5
|
+
success?: boolean;
|
|
6
|
+
message?: string;
|
|
7
|
+
user?: AuthUser;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
export declare type AuthClient = ReturnType<typeof createAuthClient>;
|
|
5
12
|
|
|
6
13
|
export declare interface AuthClientConfig {
|
|
7
14
|
baseURL?: string;
|
|
15
|
+
baseUrl?: string;
|
|
8
16
|
endpoints?: AuthEndpoints;
|
|
9
17
|
headers?: Record<string, string>;
|
|
10
18
|
credentials?: RequestCredentials;
|
|
11
|
-
|
|
19
|
+
requestAdapter?: AuthRequestAdapter;
|
|
20
|
+
adapter?: LegacyRequestAdapter;
|
|
12
21
|
}
|
|
13
22
|
|
|
14
23
|
/**
|
|
@@ -28,12 +37,20 @@ export declare interface AuthContextValue {
|
|
|
28
37
|
login: (payload: LoginPayload) => Promise<AuthUser>;
|
|
29
38
|
register: (payload: RegisterPayload) => Promise<AuthUser>;
|
|
30
39
|
logout: () => Promise<void>;
|
|
31
|
-
forgotPassword: (payload: ForgotPasswordPayload) => Promise<
|
|
32
|
-
resetPassword: (payload: ResetPasswordPayload) => Promise<
|
|
33
|
-
verifyEmail: (payload: VerifyEmailPayload) => Promise<
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
forgotPassword: (payload: ForgotPasswordPayload) => Promise<AuthActionResponse>;
|
|
41
|
+
resetPassword: (payload: ResetPasswordPayload) => Promise<AuthActionResponse>;
|
|
42
|
+
verifyEmail: (payload: VerifyEmailPayload) => Promise<AuthActionResponse>;
|
|
43
|
+
verifyTwoFactor: (payload: TwoFactorPayload) => Promise<AuthActionResponse>;
|
|
44
|
+
refreshSession: () => Promise<AuthUser | null>;
|
|
45
|
+
restoreSession: () => Promise<AuthUser | null>;
|
|
46
|
+
clearError: () => void;
|
|
47
|
+
setError: (error?: AuthError | string | null) => void;
|
|
36
48
|
setUser: (user: AuthUser | null) => void;
|
|
49
|
+
hasRole: (role: string) => boolean;
|
|
50
|
+
hasAnyRole: (roles: string[]) => boolean;
|
|
51
|
+
hasPermission: (permission: string) => boolean;
|
|
52
|
+
hasAnyPermission: (permissions: string[]) => boolean;
|
|
53
|
+
hasAllPermissions: (permissions: string[]) => boolean;
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
/**
|
|
@@ -48,6 +65,7 @@ export declare interface AuthEndpoints {
|
|
|
48
65
|
forgotPassword?: string;
|
|
49
66
|
resetPassword?: string;
|
|
50
67
|
verifyEmail?: string;
|
|
68
|
+
twoFactorVerify?: string;
|
|
51
69
|
}
|
|
52
70
|
|
|
53
71
|
export declare interface AuthError {
|
|
@@ -73,10 +91,18 @@ export declare interface AuthFormClassNames {
|
|
|
73
91
|
subtitleClassName?: string;
|
|
74
92
|
}
|
|
75
93
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
export declare const AuthLayout: default_2.FC<AuthLayoutProps>;
|
|
95
|
+
|
|
96
|
+
export declare interface AuthLayoutProps {
|
|
97
|
+
children: React.ReactNode;
|
|
98
|
+
title?: string;
|
|
99
|
+
subtitle?: string;
|
|
100
|
+
className?: string;
|
|
101
|
+
cardClassName?: string;
|
|
102
|
+
brand?: React.ReactNode;
|
|
103
|
+
footer?: React.ReactNode;
|
|
104
|
+
}
|
|
105
|
+
|
|
80
106
|
export declare const AuthProvider: default_2.FC<AuthProviderProps>;
|
|
81
107
|
|
|
82
108
|
/**
|
|
@@ -85,20 +111,46 @@ export declare const AuthProvider: default_2.FC<AuthProviderProps>;
|
|
|
85
111
|
export declare interface AuthProviderProps {
|
|
86
112
|
children: React.ReactNode;
|
|
87
113
|
baseURL?: string;
|
|
114
|
+
baseUrl?: string;
|
|
88
115
|
endpoints?: AuthEndpoints;
|
|
116
|
+
headers?: Record<string, string>;
|
|
117
|
+
credentials?: RequestCredentials;
|
|
89
118
|
onAuthError?: (error: AuthError) => void;
|
|
90
119
|
autoRefresh?: boolean;
|
|
120
|
+
autoRestore?: boolean;
|
|
91
121
|
refreshInterval?: number;
|
|
122
|
+
requestAdapter?: AuthRequestAdapter;
|
|
123
|
+
theme?: AuthTheme;
|
|
124
|
+
mock?: boolean;
|
|
125
|
+
mockStorageKey?: string;
|
|
126
|
+
mockUser?: AuthUser;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export declare type AuthRequestAdapter = (params: AuthRequestParams) => Promise<unknown>;
|
|
130
|
+
|
|
131
|
+
export declare type AuthRequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
132
|
+
|
|
133
|
+
export declare interface AuthRequestParams {
|
|
134
|
+
endpoint: string;
|
|
135
|
+
method: AuthRequestMethod;
|
|
136
|
+
data?: unknown;
|
|
137
|
+
headers?: Record<string, string>;
|
|
92
138
|
}
|
|
93
139
|
|
|
94
140
|
/**
|
|
95
141
|
* API Response Format
|
|
96
142
|
*/
|
|
97
|
-
export declare interface AuthResponse<T = AuthUser> {
|
|
143
|
+
export declare interface AuthResponse<T extends AuthUser = AuthUser> extends AuthActionResponse {
|
|
98
144
|
user?: T;
|
|
99
145
|
token?: string;
|
|
100
146
|
refreshToken?: string;
|
|
101
|
-
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export declare interface AuthTheme {
|
|
150
|
+
primaryColor?: string;
|
|
151
|
+
primaryHoverColor?: string;
|
|
152
|
+
radius?: string;
|
|
153
|
+
fontFamily?: string;
|
|
102
154
|
}
|
|
103
155
|
|
|
104
156
|
/**
|
|
@@ -123,55 +175,17 @@ export declare function cn(...classes: Array<string | undefined | false | null>)
|
|
|
123
175
|
* Creates an authenticated API client
|
|
124
176
|
*/
|
|
125
177
|
export declare function createAuthClient(config?: AuthClientConfig): {
|
|
126
|
-
/**
|
|
127
|
-
* Login with email and password
|
|
128
|
-
*/
|
|
129
178
|
login(email: string, password: string, rememberMe?: boolean): Promise<AuthResponse<AuthUser>>;
|
|
130
|
-
/**
|
|
131
|
-
* Register a new account
|
|
132
|
-
*/
|
|
133
179
|
register(payload: Record<string, unknown>): Promise<AuthResponse<AuthUser>>;
|
|
134
|
-
/**
|
|
135
|
-
* Logout the user
|
|
136
|
-
*/
|
|
137
180
|
logout(): Promise<void>;
|
|
138
|
-
/**
|
|
139
|
-
* Get current user
|
|
140
|
-
*/
|
|
141
181
|
me(): Promise<AuthResponse<AuthUser>>;
|
|
142
|
-
/**
|
|
143
|
-
* Refresh the authentication session
|
|
144
|
-
*/
|
|
145
182
|
refresh(): Promise<AuthResponse<AuthUser>>;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Reset password with token
|
|
152
|
-
*/
|
|
153
|
-
resetPassword(token: string, password: string, confirmPassword?: string): Promise<void>;
|
|
154
|
-
/**
|
|
155
|
-
* Verify email with token
|
|
156
|
-
*/
|
|
157
|
-
verifyEmail(token: string, email?: string): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Set custom headers for subsequent requests
|
|
160
|
-
*/
|
|
183
|
+
forgotPassword(email: string): Promise<AuthResponse<AuthUser>>;
|
|
184
|
+
resetPassword(token: string, password: string, confirmPassword?: string): Promise<AuthResponse<AuthUser>>;
|
|
185
|
+
verifyEmail(token: string, email?: string): Promise<AuthResponse<AuthUser>>;
|
|
186
|
+
verifyTwoFactor(code: string): Promise<AuthResponse<AuthUser>>;
|
|
161
187
|
setHeaders(newHeaders: Record<string, string>): void;
|
|
162
|
-
|
|
163
|
-
* Get current endpoints configuration
|
|
164
|
-
*/
|
|
165
|
-
getEndpoints(): {
|
|
166
|
-
login?: string;
|
|
167
|
-
register?: string;
|
|
168
|
-
logout?: string;
|
|
169
|
-
me?: string;
|
|
170
|
-
refresh?: string;
|
|
171
|
-
forgotPassword?: string;
|
|
172
|
-
resetPassword?: string;
|
|
173
|
-
verifyEmail?: string;
|
|
174
|
-
};
|
|
188
|
+
getEndpoints(): Required<AuthEndpoints>;
|
|
175
189
|
};
|
|
176
190
|
|
|
177
191
|
/**
|
|
@@ -206,6 +220,19 @@ export declare interface FormComponentProps extends AuthFormClassNames {
|
|
|
206
220
|
onError?: (error: AuthError) => void;
|
|
207
221
|
}
|
|
208
222
|
|
|
223
|
+
export declare const GuestRoute: default_2.FC<GuestRouteProps>;
|
|
224
|
+
|
|
225
|
+
export declare interface GuestRouteProps {
|
|
226
|
+
children: React.ReactNode;
|
|
227
|
+
redirectTo?: string;
|
|
228
|
+
fallback?: React.ReactNode;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Legacy adapter signature kept for backward compatibility.
|
|
233
|
+
*/
|
|
234
|
+
export declare type LegacyRequestAdapter = (url: string, options: RequestInit) => Promise<Response>;
|
|
235
|
+
|
|
209
236
|
/**
|
|
210
237
|
* LoginForm Component
|
|
211
238
|
* A ready-to-use login form with packaged default styling
|
|
@@ -231,15 +258,22 @@ export declare interface LoginPayload {
|
|
|
231
258
|
*/
|
|
232
259
|
export declare function normalizeError(error: unknown): AuthError;
|
|
233
260
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
261
|
+
export declare const OtpInput: default_2.FC<OtpInputProps>;
|
|
262
|
+
|
|
263
|
+
export declare interface OtpInputProps {
|
|
264
|
+
length?: number;
|
|
265
|
+
value?: string;
|
|
266
|
+
onChange?: (value: string) => void;
|
|
267
|
+
onComplete?: (value: string) => void;
|
|
268
|
+
disabled?: boolean;
|
|
269
|
+
className?: string;
|
|
270
|
+
inputClassName?: string;
|
|
271
|
+
}
|
|
272
|
+
|
|
239
273
|
export declare const ProtectedRoute: default_2.FC<ProtectedRouteProps>;
|
|
240
274
|
|
|
241
275
|
/**
|
|
242
|
-
*
|
|
276
|
+
* Route Props
|
|
243
277
|
*/
|
|
244
278
|
export declare interface ProtectedRouteProps {
|
|
245
279
|
children: React.ReactNode;
|
|
@@ -247,6 +281,8 @@ export declare interface ProtectedRouteProps {
|
|
|
247
281
|
fallback?: React.ReactNode;
|
|
248
282
|
roles?: string[];
|
|
249
283
|
permissions?: string[];
|
|
284
|
+
unauthorizedTo?: string;
|
|
285
|
+
requireAllPermissions?: boolean;
|
|
250
286
|
}
|
|
251
287
|
|
|
252
288
|
/**
|
|
@@ -268,10 +304,7 @@ export declare interface RegisterPayload {
|
|
|
268
304
|
[key: string]: unknown;
|
|
269
305
|
}
|
|
270
306
|
|
|
271
|
-
|
|
272
|
-
* Custom Headers and Request Adapter
|
|
273
|
-
*/
|
|
274
|
-
export declare type RequestAdapter = (url: string, options: RequestInit) => Promise<Response>;
|
|
307
|
+
export declare type RequestAdapter = LegacyRequestAdapter;
|
|
275
308
|
|
|
276
309
|
/**
|
|
277
310
|
* ResetPasswordForm Component
|
|
@@ -291,6 +324,34 @@ export declare interface ResetPasswordPayload {
|
|
|
291
324
|
confirmPassword?: string;
|
|
292
325
|
}
|
|
293
326
|
|
|
327
|
+
export declare const SocialLoginButton: default_2.FC<SocialLoginButtonProps>;
|
|
328
|
+
|
|
329
|
+
export declare interface SocialLoginButtonProps {
|
|
330
|
+
provider: "google" | "github" | "facebook" | "custom";
|
|
331
|
+
label?: string;
|
|
332
|
+
icon?: React.ReactNode;
|
|
333
|
+
onClick?: () => void;
|
|
334
|
+
className?: string;
|
|
335
|
+
disabled?: boolean;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export declare const TwoFactorForm: default_2.FC<TwoFactorFormProps>;
|
|
339
|
+
|
|
340
|
+
export declare interface TwoFactorFormProps {
|
|
341
|
+
onSuccess?: (response: AuthActionResponse) => void;
|
|
342
|
+
onError?: (error: AuthError) => void;
|
|
343
|
+
className?: string;
|
|
344
|
+
submitButtonText?: string;
|
|
345
|
+
loadingText?: string;
|
|
346
|
+
title?: string;
|
|
347
|
+
subtitle?: string;
|
|
348
|
+
length?: number;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export declare interface TwoFactorPayload {
|
|
352
|
+
code: string;
|
|
353
|
+
}
|
|
354
|
+
|
|
294
355
|
/**
|
|
295
356
|
* Hook to access auth context
|
|
296
357
|
* Must be used within an AuthProvider
|