@thetechfossil/auth2 1.2.1 → 1.2.2

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
 
3
3
  interface LinkedAccount {
4
4
  provider: 'google' | 'github';
@@ -35,7 +35,6 @@ interface RegisterData {
35
35
  name: string;
36
36
  email: string;
37
37
  password: string;
38
- frontendBaseUrl?: string;
39
38
  }
40
39
  interface UpdateUserData {
41
40
  name: string;
@@ -55,6 +54,28 @@ interface AuthConfig {
55
54
  token?: string;
56
55
  csrfEnabled?: boolean;
57
56
  }
57
+ interface Session {
58
+ id: string;
59
+ userId: string;
60
+ deviceInfo?: string;
61
+ ipAddress?: string;
62
+ lastActive: string;
63
+ createdAt: string;
64
+ }
65
+ interface MFASetup {
66
+ success: boolean;
67
+ qrCode?: string;
68
+ secret?: string;
69
+ message: string;
70
+ }
71
+ interface AuditLog {
72
+ id: string;
73
+ userId: string;
74
+ action: string;
75
+ details?: any;
76
+ ipAddress?: string;
77
+ timestamp: string;
78
+ }
58
79
  interface UseAuthReturn {
59
80
  user: User | null;
60
81
  isAuthenticated: boolean;
@@ -73,6 +94,20 @@ interface UseAuthReturn {
73
94
  unlinkOAuthProvider: (provider: OAuthProvider) => Promise<AuthResponse>;
74
95
  csrfToken: string | null;
75
96
  refreshCsrfToken: () => Promise<void>;
97
+ changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
98
+ updateAvatar: (avatar: string) => Promise<AuthResponse>;
99
+ requestEmailChange: (newEmail: string) => Promise<AuthResponse>;
100
+ verifyEmailChange: (token: string) => Promise<AuthResponse>;
101
+ generate2FA: () => Promise<MFASetup>;
102
+ enable2FA: (token: string) => Promise<AuthResponse>;
103
+ disable2FA: (token: string) => Promise<AuthResponse>;
104
+ validate2FA: (token: string) => Promise<AuthResponse>;
105
+ getSessions: () => Promise<{
106
+ success: boolean;
107
+ sessions: Session[];
108
+ }>;
109
+ revokeSession: (sessionId: string) => Promise<AuthResponse>;
110
+ revokeAllSessions: () => Promise<AuthResponse>;
76
111
  }
77
112
 
78
113
  declare class AuthService {
@@ -102,11 +137,39 @@ declare class AuthService {
102
137
  getUserById(id: string): Promise<User>;
103
138
  forgotPassword(email: string): Promise<AuthResponse>;
104
139
  resetPassword(token: string, password: string): Promise<AuthResponse>;
140
+ changePassword(oldPassword: string, newPassword: string): Promise<AuthResponse>;
141
+ updateAvatar(avatar: string): Promise<AuthResponse>;
142
+ requestEmailChange(newEmail: string): Promise<AuthResponse>;
143
+ verifyEmailChange(token: string): Promise<AuthResponse>;
144
+ generate2FA(): Promise<{
145
+ success: boolean;
146
+ qrCode?: string;
147
+ secret?: string;
148
+ message: string;
149
+ }>;
150
+ enable2FA(token: string): Promise<AuthResponse>;
151
+ disable2FA(token: string): Promise<AuthResponse>;
152
+ validate2FA(token: string): Promise<AuthResponse>;
153
+ getSessions(): Promise<{
154
+ success: boolean;
155
+ sessions: any[];
156
+ }>;
157
+ revokeSession(sessionId: string): Promise<AuthResponse>;
158
+ revokeAllSessions(): Promise<AuthResponse>;
159
+ getAuditLogs(filters?: any): Promise<{
160
+ success: boolean;
161
+ logs: any[];
162
+ }>;
163
+ adminVerifyUser(userId: string): Promise<AuthResponse>;
164
+ adminForcePasswordReset(userId: string): Promise<AuthResponse>;
165
+ adminSuspendUser(userId: string): Promise<AuthResponse>;
166
+ adminActivateUser(userId: string): Promise<AuthResponse>;
105
167
  }
106
168
 
107
169
  declare class HttpClient {
108
170
  private axiosInstance;
109
171
  private csrfToken;
172
+ private frontendBaseUrl;
110
173
  constructor(baseUrl: string, defaultHeaders?: Record<string, string>);
111
174
  get<T>(endpoint: string, headers?: Record<string, string>): Promise<T>;
112
175
  post<T>(endpoint: string, data?: any, headers?: Record<string, string>): Promise<T>;
@@ -117,24 +180,48 @@ declare class HttpClient {
117
180
  setCsrfToken(token: string): void;
118
181
  getCsrfToken(): string | null;
119
182
  removeCsrfToken(): void;
183
+ setFrontendBaseUrl(url: string): void;
184
+ getFrontendBaseUrl(): string | null;
185
+ removeFrontendBaseUrl(): void;
120
186
  private refreshCsrfToken;
121
187
  }
122
188
 
123
- interface UseAuthReturnBase {
189
+ interface AuthContextValue {
124
190
  user: User | null;
125
- isAuthenticated: boolean;
191
+ isLoaded: boolean;
192
+ isSignedIn: boolean;
126
193
  loading: boolean;
127
- register: (data: RegisterData) => Promise<AuthResponse>;
128
- login: (data: LoginData) => Promise<AuthResponse>;
194
+ signIn: (data: LoginData) => Promise<AuthResponse>;
195
+ signUp: (data: RegisterData) => Promise<AuthResponse>;
196
+ signOut: () => Promise<void>;
129
197
  verify: (data: VerifyData) => Promise<AuthResponse>;
130
198
  verifyEmailToken: (token: string) => Promise<AuthResponse>;
131
- logout: () => Promise<void>;
132
199
  updateProfile: (data: UpdateUserData) => Promise<AuthResponse>;
133
200
  getProfile: () => Promise<User>;
134
- getAllUsers: () => Promise<User[]>;
135
- getUserById: (id: string) => Promise<User>;
201
+ signInWithOAuth: (provider: OAuthProvider) => void;
202
+ linkOAuthProvider: (provider: OAuthProvider) => void;
203
+ unlinkOAuthProvider: (provider: OAuthProvider) => Promise<AuthResponse>;
204
+ forgotPassword: (email: string) => Promise<AuthResponse>;
205
+ resetPassword: (token: string, password: string) => Promise<AuthResponse>;
206
+ changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
207
+ updateAvatar: (avatar: string) => Promise<AuthResponse>;
208
+ requestEmailChange: (newEmail: string) => Promise<AuthResponse>;
209
+ verifyEmailChange: (token: string) => Promise<AuthResponse>;
210
+ generate2FA: () => Promise<any>;
211
+ enable2FA: (token: string) => Promise<AuthResponse>;
212
+ disable2FA: (token: string) => Promise<AuthResponse>;
213
+ validate2FA: (token: string) => Promise<AuthResponse>;
214
+ getSessions: () => Promise<any>;
215
+ revokeSession: (sessionId: string) => Promise<AuthResponse>;
216
+ revokeAllSessions: () => Promise<AuthResponse>;
217
+ authService: AuthService;
136
218
  }
137
- declare const useAuth: (config: AuthConfig) => UseAuthReturnBase;
219
+ interface AuthProviderProps {
220
+ children: ReactNode;
221
+ config?: Partial<AuthConfig>;
222
+ }
223
+ declare const AuthProvider: React.FC<AuthProviderProps>;
224
+ declare const useAuth$1: () => AuthContextValue;
138
225
 
139
226
  interface LoginFormProps {
140
227
  onSuccess?: (response: {
@@ -188,20 +275,170 @@ interface EmailVerificationPageProps {
188
275
  }
189
276
  declare const EmailVerificationPage: React.FC<EmailVerificationPageProps>;
190
277
 
278
+ interface SignInProps {
279
+ redirectUrl?: string;
280
+ appearance?: {
281
+ elements?: {
282
+ formButtonPrimary?: React.CSSProperties;
283
+ card?: React.CSSProperties;
284
+ headerTitle?: React.CSSProperties;
285
+ formFieldInput?: React.CSSProperties;
286
+ };
287
+ };
288
+ routing?: 'path' | 'virtual';
289
+ path?: string;
290
+ }
291
+ declare const SignIn: React.FC<SignInProps>;
292
+
293
+ interface SignUpProps {
294
+ redirectUrl?: string;
295
+ appearance?: {
296
+ elements?: {
297
+ formButtonPrimary?: React.CSSProperties;
298
+ card?: React.CSSProperties;
299
+ headerTitle?: React.CSSProperties;
300
+ formFieldInput?: React.CSSProperties;
301
+ };
302
+ };
303
+ }
304
+ declare const SignUp: React.FC<SignUpProps>;
305
+
306
+ interface SignOutProps {
307
+ redirectUrl?: string;
308
+ }
309
+ declare const SignOut: React.FC<SignOutProps>;
310
+
311
+ interface UserButtonProps {
312
+ showName?: boolean;
313
+ appearance?: {
314
+ elements?: {
315
+ userButtonBox?: React.CSSProperties;
316
+ userButtonTrigger?: React.CSSProperties;
317
+ userButtonPopoverCard?: React.CSSProperties;
318
+ };
319
+ };
320
+ }
321
+ declare const UserButton: React.FC<UserButtonProps>;
322
+
323
+ interface ProtectedRouteProps {
324
+ children: ReactNode;
325
+ fallback?: ReactNode;
326
+ redirectTo?: string;
327
+ }
328
+ declare const ProtectedRoute: React.FC<ProtectedRouteProps>;
329
+
330
+ interface PublicRouteProps {
331
+ children: ReactNode;
332
+ redirectTo?: string;
333
+ }
334
+ declare const PublicRoute: React.FC<PublicRouteProps>;
335
+
336
+ interface VerifyEmailProps {
337
+ token?: string;
338
+ onSuccess?: () => void;
339
+ onError?: (error: string) => void;
340
+ }
341
+ declare const VerifyEmail: React.FC<VerifyEmailProps>;
342
+
343
+ interface ForgotPasswordProps {
344
+ appearance?: {
345
+ elements?: {
346
+ formButtonPrimary?: React.CSSProperties;
347
+ card?: React.CSSProperties;
348
+ headerTitle?: React.CSSProperties;
349
+ formFieldInput?: React.CSSProperties;
350
+ };
351
+ };
352
+ }
353
+ declare const ForgotPassword: React.FC<ForgotPasswordProps>;
354
+
355
+ interface ResetPasswordProps {
356
+ token?: string;
357
+ appearance?: {
358
+ elements?: {
359
+ formButtonPrimary?: React.CSSProperties;
360
+ card?: React.CSSProperties;
361
+ headerTitle?: React.CSSProperties;
362
+ formFieldInput?: React.CSSProperties;
363
+ };
364
+ };
365
+ }
366
+ declare const ResetPassword: React.FC<ResetPasswordProps>;
367
+
368
+ interface ChangePasswordProps {
369
+ onSuccess?: () => void;
370
+ appearance?: {
371
+ elements?: {
372
+ formButtonPrimary?: React.CSSProperties;
373
+ card?: React.CSSProperties;
374
+ headerTitle?: React.CSSProperties;
375
+ formFieldInput?: React.CSSProperties;
376
+ };
377
+ };
378
+ }
379
+ declare const ChangePassword: React.FC<ChangePasswordProps>;
380
+
381
+ interface UserProfileProps {
382
+ showAvatar?: boolean;
383
+ showEmailChange?: boolean;
384
+ showPasswordChange?: boolean;
385
+ }
386
+ declare const UserProfile: React.FC<UserProfileProps>;
387
+
388
+ interface UseAuthReturnBase {
389
+ user: User | null;
390
+ isAuthenticated: boolean;
391
+ loading: boolean;
392
+ register: (data: RegisterData) => Promise<AuthResponse>;
393
+ login: (data: LoginData) => Promise<AuthResponse>;
394
+ verify: (data: VerifyData) => Promise<AuthResponse>;
395
+ verifyEmailToken: (token: string) => Promise<AuthResponse>;
396
+ logout: () => Promise<void>;
397
+ updateProfile: (data: UpdateUserData) => Promise<AuthResponse>;
398
+ getProfile: () => Promise<User>;
399
+ getAllUsers: () => Promise<User[]>;
400
+ getUserById: (id: string) => Promise<User>;
401
+ }
402
+ declare const useAuth: (config: AuthConfig) => UseAuthReturnBase;
403
+
191
404
  declare const index$1_AuthFlow: typeof AuthFlow;
405
+ declare const index$1_AuthProvider: typeof AuthProvider;
406
+ declare const index$1_ChangePassword: typeof ChangePassword;
192
407
  declare const index$1_EmailVerificationPage: typeof EmailVerificationPage;
408
+ declare const index$1_ForgotPassword: typeof ForgotPassword;
193
409
  declare const index$1_LoginForm: typeof LoginForm;
194
410
  declare const index$1_OtpForm: typeof OtpForm;
411
+ declare const index$1_ProtectedRoute: typeof ProtectedRoute;
412
+ declare const index$1_PublicRoute: typeof PublicRoute;
195
413
  declare const index$1_RegisterForm: typeof RegisterForm;
196
- declare const index$1_useAuth: typeof useAuth;
414
+ declare const index$1_ResetPassword: typeof ResetPassword;
415
+ declare const index$1_SignIn: typeof SignIn;
416
+ declare const index$1_SignOut: typeof SignOut;
417
+ declare const index$1_SignUp: typeof SignUp;
418
+ declare const index$1_UserButton: typeof UserButton;
419
+ declare const index$1_UserProfile: typeof UserProfile;
420
+ declare const index$1_VerifyEmail: typeof VerifyEmail;
197
421
  declare namespace index$1 {
198
422
  export {
199
423
  index$1_AuthFlow as AuthFlow,
424
+ index$1_AuthProvider as AuthProvider,
425
+ index$1_ChangePassword as ChangePassword,
200
426
  index$1_EmailVerificationPage as EmailVerificationPage,
427
+ index$1_ForgotPassword as ForgotPassword,
201
428
  index$1_LoginForm as LoginForm,
202
429
  index$1_OtpForm as OtpForm,
430
+ index$1_ProtectedRoute as ProtectedRoute,
431
+ index$1_PublicRoute as PublicRoute,
203
432
  index$1_RegisterForm as RegisterForm,
204
- index$1_useAuth as useAuth,
433
+ index$1_ResetPassword as ResetPassword,
434
+ index$1_SignIn as SignIn,
435
+ index$1_SignOut as SignOut,
436
+ index$1_SignUp as SignUp,
437
+ index$1_UserButton as UserButton,
438
+ index$1_UserProfile as UserProfile,
439
+ index$1_VerifyEmail as VerifyEmail,
440
+ useAuth$1 as useAuth,
441
+ useAuth as useAuthLegacy,
205
442
  };
206
443
  }
207
444
 
@@ -225,4 +462,4 @@ declare namespace index {
225
462
  };
226
463
  }
227
464
 
228
- export { AuthConfig, AuthResponse, AuthService, CsrfTokenResponse, HttpClient, LinkedAccount, LoginData, OAuthConfig, OAuthProvider, RegisterData, UpdateUserData, UseAuthReturn, User, VerifyData, index as node, index$1 as react };
465
+ export { AuditLog, AuthConfig, AuthFlow, AuthProvider, AuthResponse, AuthService, ChangePassword, CsrfTokenResponse, EmailVerificationPage, ForgotPassword, HttpClient, LinkedAccount, LoginData, LoginForm, MFASetup, OAuthConfig, OAuthProvider, OtpForm, ProtectedRoute, PublicRoute, RegisterData, RegisterForm, ResetPassword, Session, SignIn, SignOut, SignUp, UpdateUserData, UseAuthReturn, User, UserButton, UserProfile, VerifyData, VerifyEmail, index as node, index$1 as react, useAuth$1 as useAuth };