@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.
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
+ import { NextRequest, NextResponse } from 'next/server';
2
3
 
3
4
  interface LinkedAccount {
4
5
  provider: 'google' | 'github';
@@ -35,7 +36,6 @@ interface RegisterData {
35
36
  name: string;
36
37
  email: string;
37
38
  password: string;
38
- frontendBaseUrl?: string;
39
39
  }
40
40
  interface UpdateUserData {
41
41
  name: string;
@@ -55,6 +55,28 @@ interface AuthConfig {
55
55
  token?: string;
56
56
  csrfEnabled?: boolean;
57
57
  }
58
+ interface Session {
59
+ id: string;
60
+ userId: string;
61
+ deviceInfo?: string;
62
+ ipAddress?: string;
63
+ lastActive: string;
64
+ createdAt: string;
65
+ }
66
+ interface MFASetup {
67
+ success: boolean;
68
+ qrCode?: string;
69
+ secret?: string;
70
+ message: string;
71
+ }
72
+ interface AuditLog {
73
+ id: string;
74
+ userId: string;
75
+ action: string;
76
+ details?: any;
77
+ ipAddress?: string;
78
+ timestamp: string;
79
+ }
58
80
  interface UseAuthReturn {
59
81
  user: User | null;
60
82
  isAuthenticated: boolean;
@@ -73,6 +95,20 @@ interface UseAuthReturn {
73
95
  unlinkOAuthProvider: (provider: OAuthProvider) => Promise<AuthResponse>;
74
96
  csrfToken: string | null;
75
97
  refreshCsrfToken: () => Promise<void>;
98
+ changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
99
+ updateAvatar: (avatar: string) => Promise<AuthResponse>;
100
+ requestEmailChange: (newEmail: string) => Promise<AuthResponse>;
101
+ verifyEmailChange: (token: string) => Promise<AuthResponse>;
102
+ generate2FA: () => Promise<MFASetup>;
103
+ enable2FA: (token: string) => Promise<AuthResponse>;
104
+ disable2FA: (token: string) => Promise<AuthResponse>;
105
+ validate2FA: (token: string) => Promise<AuthResponse>;
106
+ getSessions: () => Promise<{
107
+ success: boolean;
108
+ sessions: Session[];
109
+ }>;
110
+ revokeSession: (sessionId: string) => Promise<AuthResponse>;
111
+ revokeAllSessions: () => Promise<AuthResponse>;
76
112
  }
77
113
 
78
114
  declare class AuthService {
@@ -102,11 +138,39 @@ declare class AuthService {
102
138
  getUserById(id: string): Promise<User>;
103
139
  forgotPassword(email: string): Promise<AuthResponse>;
104
140
  resetPassword(token: string, password: string): Promise<AuthResponse>;
141
+ changePassword(oldPassword: string, newPassword: string): Promise<AuthResponse>;
142
+ updateAvatar(avatar: string): Promise<AuthResponse>;
143
+ requestEmailChange(newEmail: string): Promise<AuthResponse>;
144
+ verifyEmailChange(token: string): Promise<AuthResponse>;
145
+ generate2FA(): Promise<{
146
+ success: boolean;
147
+ qrCode?: string;
148
+ secret?: string;
149
+ message: string;
150
+ }>;
151
+ enable2FA(token: string): Promise<AuthResponse>;
152
+ disable2FA(token: string): Promise<AuthResponse>;
153
+ validate2FA(token: string): Promise<AuthResponse>;
154
+ getSessions(): Promise<{
155
+ success: boolean;
156
+ sessions: any[];
157
+ }>;
158
+ revokeSession(sessionId: string): Promise<AuthResponse>;
159
+ revokeAllSessions(): Promise<AuthResponse>;
160
+ getAuditLogs(filters?: any): Promise<{
161
+ success: boolean;
162
+ logs: any[];
163
+ }>;
164
+ adminVerifyUser(userId: string): Promise<AuthResponse>;
165
+ adminForcePasswordReset(userId: string): Promise<AuthResponse>;
166
+ adminSuspendUser(userId: string): Promise<AuthResponse>;
167
+ adminActivateUser(userId: string): Promise<AuthResponse>;
105
168
  }
106
169
 
107
170
  declare class HttpClient {
108
171
  private axiosInstance;
109
172
  private csrfToken;
173
+ private frontendBaseUrl;
110
174
  constructor(baseUrl: string, defaultHeaders?: Record<string, string>);
111
175
  get<T>(endpoint: string, headers?: Record<string, string>): Promise<T>;
112
176
  post<T>(endpoint: string, data?: any, headers?: Record<string, string>): Promise<T>;
@@ -117,6 +181,9 @@ declare class HttpClient {
117
181
  setCsrfToken(token: string): void;
118
182
  getCsrfToken(): string | null;
119
183
  removeCsrfToken(): void;
184
+ setFrontendBaseUrl(url: string): void;
185
+ getFrontendBaseUrl(): string | null;
186
+ removeFrontendBaseUrl(): void;
120
187
  private refreshCsrfToken;
121
188
  }
122
189
 
@@ -134,7 +201,44 @@ interface UseAuthReturnBase {
134
201
  getAllUsers: () => Promise<User[]>;
135
202
  getUserById: (id: string) => Promise<User>;
136
203
  }
137
- declare const useAuth: (config: AuthConfig) => UseAuthReturnBase;
204
+ declare const useAuth$1: (config: AuthConfig) => UseAuthReturnBase;
205
+
206
+ interface AuthContextValue {
207
+ user: User | null;
208
+ isLoaded: boolean;
209
+ isSignedIn: boolean;
210
+ loading: boolean;
211
+ signIn: (data: LoginData) => Promise<AuthResponse>;
212
+ signUp: (data: RegisterData) => Promise<AuthResponse>;
213
+ signOut: () => Promise<void>;
214
+ verify: (data: VerifyData) => Promise<AuthResponse>;
215
+ verifyEmailToken: (token: string) => Promise<AuthResponse>;
216
+ updateProfile: (data: UpdateUserData) => Promise<AuthResponse>;
217
+ getProfile: () => Promise<User>;
218
+ signInWithOAuth: (provider: OAuthProvider) => void;
219
+ linkOAuthProvider: (provider: OAuthProvider) => void;
220
+ unlinkOAuthProvider: (provider: OAuthProvider) => Promise<AuthResponse>;
221
+ forgotPassword: (email: string) => Promise<AuthResponse>;
222
+ resetPassword: (token: string, password: string) => Promise<AuthResponse>;
223
+ changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
224
+ updateAvatar: (avatar: string) => Promise<AuthResponse>;
225
+ requestEmailChange: (newEmail: string) => Promise<AuthResponse>;
226
+ verifyEmailChange: (token: string) => Promise<AuthResponse>;
227
+ generate2FA: () => Promise<any>;
228
+ enable2FA: (token: string) => Promise<AuthResponse>;
229
+ disable2FA: (token: string) => Promise<AuthResponse>;
230
+ validate2FA: (token: string) => Promise<AuthResponse>;
231
+ getSessions: () => Promise<any>;
232
+ revokeSession: (sessionId: string) => Promise<AuthResponse>;
233
+ revokeAllSessions: () => Promise<AuthResponse>;
234
+ authService: AuthService;
235
+ }
236
+ interface AuthProviderProps {
237
+ children: ReactNode;
238
+ config?: Partial<AuthConfig>;
239
+ }
240
+ declare const AuthProvider: React.FC<AuthProviderProps>;
241
+ declare const useAuth: () => AuthContextValue;
138
242
 
139
243
  interface LoginFormProps {
140
244
  onSuccess?: (response: {
@@ -188,6 +292,116 @@ interface EmailVerificationPageProps {
188
292
  }
189
293
  declare const EmailVerificationPage: React.FC<EmailVerificationPageProps>;
190
294
 
295
+ interface SignInProps {
296
+ redirectUrl?: string;
297
+ appearance?: {
298
+ elements?: {
299
+ formButtonPrimary?: React.CSSProperties;
300
+ card?: React.CSSProperties;
301
+ headerTitle?: React.CSSProperties;
302
+ formFieldInput?: React.CSSProperties;
303
+ };
304
+ };
305
+ routing?: 'path' | 'virtual';
306
+ path?: string;
307
+ }
308
+ declare const SignIn: React.FC<SignInProps>;
309
+
310
+ interface SignUpProps {
311
+ redirectUrl?: string;
312
+ appearance?: {
313
+ elements?: {
314
+ formButtonPrimary?: React.CSSProperties;
315
+ card?: React.CSSProperties;
316
+ headerTitle?: React.CSSProperties;
317
+ formFieldInput?: React.CSSProperties;
318
+ };
319
+ };
320
+ }
321
+ declare const SignUp: React.FC<SignUpProps>;
322
+
323
+ interface SignOutProps {
324
+ redirectUrl?: string;
325
+ }
326
+ declare const SignOut: React.FC<SignOutProps>;
327
+
328
+ interface UserButtonProps {
329
+ showName?: boolean;
330
+ appearance?: {
331
+ elements?: {
332
+ userButtonBox?: React.CSSProperties;
333
+ userButtonTrigger?: React.CSSProperties;
334
+ userButtonPopoverCard?: React.CSSProperties;
335
+ };
336
+ };
337
+ }
338
+ declare const UserButton: React.FC<UserButtonProps>;
339
+
340
+ interface ProtectedRouteProps {
341
+ children: ReactNode;
342
+ fallback?: ReactNode;
343
+ redirectTo?: string;
344
+ }
345
+ declare const ProtectedRoute: React.FC<ProtectedRouteProps>;
346
+
347
+ interface PublicRouteProps {
348
+ children: ReactNode;
349
+ redirectTo?: string;
350
+ }
351
+ declare const PublicRoute: React.FC<PublicRouteProps>;
352
+
353
+ interface VerifyEmailProps {
354
+ token?: string;
355
+ onSuccess?: () => void;
356
+ onError?: (error: string) => void;
357
+ }
358
+ declare const VerifyEmail: React.FC<VerifyEmailProps>;
359
+
360
+ interface ForgotPasswordProps {
361
+ appearance?: {
362
+ elements?: {
363
+ formButtonPrimary?: React.CSSProperties;
364
+ card?: React.CSSProperties;
365
+ headerTitle?: React.CSSProperties;
366
+ formFieldInput?: React.CSSProperties;
367
+ };
368
+ };
369
+ }
370
+ declare const ForgotPassword: React.FC<ForgotPasswordProps>;
371
+
372
+ interface ResetPasswordProps {
373
+ token?: string;
374
+ appearance?: {
375
+ elements?: {
376
+ formButtonPrimary?: React.CSSProperties;
377
+ card?: React.CSSProperties;
378
+ headerTitle?: React.CSSProperties;
379
+ formFieldInput?: React.CSSProperties;
380
+ };
381
+ };
382
+ }
383
+ declare const ResetPassword: React.FC<ResetPasswordProps>;
384
+
385
+ interface ChangePasswordProps {
386
+ onSuccess?: () => void;
387
+ appearance?: {
388
+ elements?: {
389
+ formButtonPrimary?: React.CSSProperties;
390
+ card?: React.CSSProperties;
391
+ headerTitle?: React.CSSProperties;
392
+ formFieldInput?: React.CSSProperties;
393
+ };
394
+ };
395
+ }
396
+ declare const ChangePassword: React.FC<ChangePasswordProps>;
397
+
398
+ interface UserProfileProps {
399
+ showAvatar?: boolean;
400
+ showEmailChange?: boolean;
401
+ showPasswordChange?: boolean;
402
+ }
403
+ declare const UserProfile: React.FC<UserProfileProps>;
404
+
191
405
  interface UseNextAuthReturn {
192
406
  user: User | null;
193
407
  isAuthenticated: boolean;
@@ -229,4 +443,39 @@ declare class NextServerAuth extends AuthClient {
229
443
  static createAuthenticatedClient(config: AuthConfig, token: string): NextServerAuth;
230
444
  }
231
445
 
232
- export { AuthConfig, AuthFlow, AuthResponse, AuthService, CsrfTokenResponse, EmailVerificationPage, HttpClient, LinkedAccount, LoginData, LoginForm, NextServerAuth, OAuthConfig, OAuthProvider, OtpForm, RegisterData, RegisterForm, UpdateUserData, UseAuthReturn, User, VerifyData, useAuth, useNextAuth };
446
+ interface AuthServerConfig {
447
+ authApiUrl?: string;
448
+ tokenCookieName?: string;
449
+ }
450
+ declare class AuthServer {
451
+ private config;
452
+ constructor(config?: AuthServerConfig);
453
+ getToken(): Promise<string | null>;
454
+ getCurrentUser(): Promise<User | null>;
455
+ isAuthenticated(): Promise<boolean>;
456
+ requireAuth(redirectTo?: string): Promise<User>;
457
+ redirectIfAuthenticated(redirectTo?: string): Promise<void>;
458
+ getProfile(): Promise<User | null>;
459
+ }
460
+ declare function getAuthServer(config?: AuthServerConfig): AuthServer;
461
+ declare function currentUser(): Promise<User | null>;
462
+ declare function auth(): Promise<{
463
+ user: User | null;
464
+ userId: string | null;
465
+ isAuthenticated: boolean;
466
+ token: string | null;
467
+ }>;
468
+ declare function requireAuth(redirectTo?: string): Promise<User>;
469
+ declare function redirectIfAuthenticated(redirectTo?: string): Promise<void>;
470
+
471
+ interface AuthMiddlewareConfig {
472
+ publicRoutes?: string[];
473
+ protectedRoutes?: string[];
474
+ loginUrl?: string;
475
+ afterLoginUrl?: string;
476
+ tokenCookieName?: string;
477
+ }
478
+ declare function authMiddleware(config?: AuthMiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
479
+ declare function createAuthMiddleware(config?: AuthMiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
480
+
481
+ export { AuditLog, AuthConfig, AuthFlow, AuthProvider, AuthResponse, AuthServer, AuthService, ChangePassword, CsrfTokenResponse, EmailVerificationPage, ForgotPassword, HttpClient, LinkedAccount, LoginData, LoginForm, MFASetup, NextServerAuth, OAuthConfig, OAuthProvider, OtpForm, ProtectedRoute, PublicRoute, RegisterData, RegisterForm, ResetPassword, Session, SignIn, SignOut, SignUp, UpdateUserData, UseAuthReturn, User, UserButton, UserProfile, VerifyData, VerifyEmail, auth, authMiddleware, createAuthMiddleware, currentUser, getAuthServer, redirectIfAuthenticated, requireAuth, useAuth, useAuth$1 as useAuthLegacy, useNextAuth };