@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/README.NEW.md +365 -0
- package/dist/index.components.d.ts +112 -2
- package/dist/index.components.js +1995 -19
- package/dist/index.components.js.map +1 -1
- package/dist/index.components.mjs +1986 -21
- package/dist/index.components.mjs.map +1 -1
- package/dist/index.d.ts +250 -13
- package/dist/index.js +2392 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2376 -134
- package/dist/index.mjs.map +1 -1
- package/dist/index.next.d.ts +253 -4
- package/dist/index.next.js +2514 -133
- package/dist/index.next.js.map +1 -1
- package/dist/index.next.mjs +2494 -134
- package/dist/index.next.mjs.map +1 -1
- package/dist/index.next.server.d.ts +68 -2
- package/dist/index.next.server.js +184 -18
- package/dist/index.next.server.js.map +1 -1
- package/dist/index.next.server.mjs +184 -18
- package/dist/index.next.server.mjs.map +1 -1
- package/dist/index.node.d.ts +68 -2
- package/dist/index.node.js +184 -18
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +184 -18
- package/dist/index.node.mjs.map +1 -1
- package/package.json +40 -18
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __export = (target, all) => {
|
|
|
16
16
|
var HttpClient = class {
|
|
17
17
|
constructor(baseUrl, defaultHeaders = {}) {
|
|
18
18
|
this.csrfToken = null;
|
|
19
|
+
this.frontendBaseUrl = null;
|
|
19
20
|
this.axiosInstance = axios__default.default.create({
|
|
20
21
|
baseURL: baseUrl.replace(/\/$/, ""),
|
|
21
22
|
headers: {
|
|
@@ -32,6 +33,9 @@ var HttpClient = class {
|
|
|
32
33
|
if (this.csrfToken && ["post", "put", "delete", "patch"].includes(config.method?.toLowerCase() || "")) {
|
|
33
34
|
config.headers["x-csrf-token"] = this.csrfToken;
|
|
34
35
|
}
|
|
36
|
+
if (this.frontendBaseUrl) {
|
|
37
|
+
config.headers["X-Frontend-URL"] = this.frontendBaseUrl;
|
|
38
|
+
}
|
|
35
39
|
return config;
|
|
36
40
|
},
|
|
37
41
|
(error) => Promise.reject(error)
|
|
@@ -87,6 +91,15 @@ var HttpClient = class {
|
|
|
87
91
|
removeCsrfToken() {
|
|
88
92
|
this.csrfToken = null;
|
|
89
93
|
}
|
|
94
|
+
setFrontendBaseUrl(url) {
|
|
95
|
+
this.frontendBaseUrl = url;
|
|
96
|
+
}
|
|
97
|
+
getFrontendBaseUrl() {
|
|
98
|
+
return this.frontendBaseUrl;
|
|
99
|
+
}
|
|
100
|
+
removeFrontendBaseUrl() {
|
|
101
|
+
this.frontendBaseUrl = null;
|
|
102
|
+
}
|
|
90
103
|
async refreshCsrfToken() {
|
|
91
104
|
try {
|
|
92
105
|
const response = await this.axiosInstance.get("/api/v1/auth/csrf-token");
|
|
@@ -109,6 +122,12 @@ var AuthService = class {
|
|
|
109
122
|
};
|
|
110
123
|
this.httpClient = new HttpClient(this.config.baseUrl);
|
|
111
124
|
this.loadTokenFromStorage();
|
|
125
|
+
if (typeof window !== "undefined") {
|
|
126
|
+
const frontendBaseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
|
|
127
|
+
if (frontendBaseUrl) {
|
|
128
|
+
this.httpClient.setFrontendBaseUrl(frontendBaseUrl);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
112
131
|
if (this.config.csrfEnabled && typeof window !== "undefined") {
|
|
113
132
|
this.refreshCsrfToken();
|
|
114
133
|
}
|
|
@@ -225,11 +244,7 @@ var AuthService = class {
|
|
|
225
244
|
throw new Error(response.message || "Login failed");
|
|
226
245
|
}
|
|
227
246
|
async register(data) {
|
|
228
|
-
const
|
|
229
|
-
if (!registerData.frontendBaseUrl && typeof window !== "undefined") {
|
|
230
|
-
registerData.frontendBaseUrl = process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
|
|
231
|
-
}
|
|
232
|
-
const response = await this.httpClient.post("/api/v1/auth/register", registerData);
|
|
247
|
+
const response = await this.httpClient.post("/api/v1/auth/register", data);
|
|
233
248
|
if (response.success && response.message === "Registration data saved. Verification email sent. Please check your inbox.") {
|
|
234
249
|
return response;
|
|
235
250
|
}
|
|
@@ -245,15 +260,33 @@ var AuthService = class {
|
|
|
245
260
|
return response;
|
|
246
261
|
}
|
|
247
262
|
async verifyEmailToken(token) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
263
|
+
try {
|
|
264
|
+
const response = await this.httpClient.get(`/api/v1/auth/verify-email?token=${token}`);
|
|
265
|
+
if (response.success && response.token) {
|
|
266
|
+
this.token = response.token;
|
|
267
|
+
this.httpClient.setAuthToken(response.token);
|
|
268
|
+
this.saveTokenToStorage(response.token);
|
|
269
|
+
}
|
|
270
|
+
return response;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
if (error.response?.data) {
|
|
273
|
+
return {
|
|
274
|
+
success: false,
|
|
275
|
+
message: error.response.data.message || "Email verification failed"
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
success: false,
|
|
280
|
+
message: error.message || "Network error occurred"
|
|
281
|
+
};
|
|
253
282
|
}
|
|
254
|
-
return response;
|
|
255
283
|
}
|
|
256
284
|
async logout() {
|
|
285
|
+
try {
|
|
286
|
+
await this.httpClient.post("/api/v1/auth/logout", {});
|
|
287
|
+
} catch (error) {
|
|
288
|
+
console.warn("Failed to call logout endpoint:", error);
|
|
289
|
+
}
|
|
257
290
|
this.token = null;
|
|
258
291
|
this.httpClient.removeAuthToken();
|
|
259
292
|
this.httpClient.removeCsrfToken();
|
|
@@ -290,9 +323,6 @@ var AuthService = class {
|
|
|
290
323
|
return response.user;
|
|
291
324
|
}
|
|
292
325
|
async forgotPassword(email) {
|
|
293
|
-
if (typeof window !== "undefined") {
|
|
294
|
-
process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
|
|
295
|
-
}
|
|
296
326
|
const response = await this.httpClient.post("/api/v1/auth/forgot-password", { email });
|
|
297
327
|
return response;
|
|
298
328
|
}
|
|
@@ -300,70 +330,208 @@ var AuthService = class {
|
|
|
300
330
|
const response = await this.httpClient.post("/api/v1/auth/reset-password", { token, password });
|
|
301
331
|
return response;
|
|
302
332
|
}
|
|
333
|
+
async changePassword(oldPassword, newPassword) {
|
|
334
|
+
if (!this.token) {
|
|
335
|
+
throw new Error("Not authenticated");
|
|
336
|
+
}
|
|
337
|
+
const response = await this.httpClient.post("/api/v1/user/change-password", {
|
|
338
|
+
oldPassword,
|
|
339
|
+
newPassword
|
|
340
|
+
});
|
|
341
|
+
return response;
|
|
342
|
+
}
|
|
343
|
+
async updateAvatar(avatar) {
|
|
344
|
+
if (!this.token) {
|
|
345
|
+
throw new Error("Not authenticated");
|
|
346
|
+
}
|
|
347
|
+
const response = await this.httpClient.post("/api/v1/user/update/avatar", { avatar });
|
|
348
|
+
if (response.success && response.token) {
|
|
349
|
+
this.token = response.token;
|
|
350
|
+
this.httpClient.setAuthToken(response.token);
|
|
351
|
+
this.saveTokenToStorage(response.token);
|
|
352
|
+
}
|
|
353
|
+
return response;
|
|
354
|
+
}
|
|
355
|
+
async requestEmailChange(newEmail) {
|
|
356
|
+
if (!this.token) {
|
|
357
|
+
throw new Error("Not authenticated");
|
|
358
|
+
}
|
|
359
|
+
const response = await this.httpClient.post("/api/v1/user/request-email-change", {
|
|
360
|
+
newEmail
|
|
361
|
+
});
|
|
362
|
+
return response;
|
|
363
|
+
}
|
|
364
|
+
async verifyEmailChange(token) {
|
|
365
|
+
const response = await this.httpClient.get(`/api/v1/user/verify-email-change?token=${token}`);
|
|
366
|
+
if (response.success && response.token) {
|
|
367
|
+
this.token = response.token;
|
|
368
|
+
this.httpClient.setAuthToken(response.token);
|
|
369
|
+
this.saveTokenToStorage(response.token);
|
|
370
|
+
}
|
|
371
|
+
return response;
|
|
372
|
+
}
|
|
373
|
+
// 2FA / MFA Methods
|
|
374
|
+
async generate2FA() {
|
|
375
|
+
if (!this.token) {
|
|
376
|
+
throw new Error("Not authenticated");
|
|
377
|
+
}
|
|
378
|
+
const response = await this.httpClient.post(
|
|
379
|
+
"/api/v1/mfa/generate",
|
|
380
|
+
{}
|
|
381
|
+
);
|
|
382
|
+
return response;
|
|
383
|
+
}
|
|
384
|
+
async enable2FA(token) {
|
|
385
|
+
if (!this.token) {
|
|
386
|
+
throw new Error("Not authenticated");
|
|
387
|
+
}
|
|
388
|
+
const response = await this.httpClient.post("/api/v1/mfa/enable", { token });
|
|
389
|
+
return response;
|
|
390
|
+
}
|
|
391
|
+
async disable2FA(token) {
|
|
392
|
+
if (!this.token) {
|
|
393
|
+
throw new Error("Not authenticated");
|
|
394
|
+
}
|
|
395
|
+
const response = await this.httpClient.post("/api/v1/mfa/disable", { token });
|
|
396
|
+
return response;
|
|
397
|
+
}
|
|
398
|
+
async validate2FA(token) {
|
|
399
|
+
if (!this.token) {
|
|
400
|
+
throw new Error("Not authenticated");
|
|
401
|
+
}
|
|
402
|
+
const response = await this.httpClient.post("/api/v1/mfa/validate", { token });
|
|
403
|
+
return response;
|
|
404
|
+
}
|
|
405
|
+
// Session Management Methods
|
|
406
|
+
async getSessions() {
|
|
407
|
+
if (!this.token) {
|
|
408
|
+
throw new Error("Not authenticated");
|
|
409
|
+
}
|
|
410
|
+
const response = await this.httpClient.get("/api/v1/session");
|
|
411
|
+
return response;
|
|
412
|
+
}
|
|
413
|
+
async revokeSession(sessionId) {
|
|
414
|
+
if (!this.token) {
|
|
415
|
+
throw new Error("Not authenticated");
|
|
416
|
+
}
|
|
417
|
+
const response = await this.httpClient.delete(`/api/v1/session/${sessionId}`);
|
|
418
|
+
return response;
|
|
419
|
+
}
|
|
420
|
+
async revokeAllSessions() {
|
|
421
|
+
if (!this.token) {
|
|
422
|
+
throw new Error("Not authenticated");
|
|
423
|
+
}
|
|
424
|
+
const response = await this.httpClient.delete("/api/v1/session/revoke/all");
|
|
425
|
+
this.token = null;
|
|
426
|
+
this.httpClient.removeAuthToken();
|
|
427
|
+
this.removeTokenFromStorage();
|
|
428
|
+
return response;
|
|
429
|
+
}
|
|
430
|
+
// Admin Methods
|
|
431
|
+
async getAuditLogs(filters) {
|
|
432
|
+
if (!this.token) {
|
|
433
|
+
throw new Error("Not authenticated");
|
|
434
|
+
}
|
|
435
|
+
const response = await this.httpClient.get(
|
|
436
|
+
"/api/v1/admin/audit-logs",
|
|
437
|
+
filters
|
|
438
|
+
);
|
|
439
|
+
return response;
|
|
440
|
+
}
|
|
441
|
+
async adminVerifyUser(userId) {
|
|
442
|
+
if (!this.token) {
|
|
443
|
+
throw new Error("Not authenticated");
|
|
444
|
+
}
|
|
445
|
+
const response = await this.httpClient.post(`/api/v1/admin/verify-user/${userId}`, {});
|
|
446
|
+
return response;
|
|
447
|
+
}
|
|
448
|
+
async adminForcePasswordReset(userId) {
|
|
449
|
+
if (!this.token) {
|
|
450
|
+
throw new Error("Not authenticated");
|
|
451
|
+
}
|
|
452
|
+
const response = await this.httpClient.post(`/api/v1/admin/force-password-reset/${userId}`, {});
|
|
453
|
+
return response;
|
|
454
|
+
}
|
|
455
|
+
async adminSuspendUser(userId) {
|
|
456
|
+
if (!this.token) {
|
|
457
|
+
throw new Error("Not authenticated");
|
|
458
|
+
}
|
|
459
|
+
const response = await this.httpClient.post(`/api/v1/admin/suspend-user/${userId}`, {});
|
|
460
|
+
return response;
|
|
461
|
+
}
|
|
462
|
+
async adminActivateUser(userId) {
|
|
463
|
+
if (!this.token) {
|
|
464
|
+
throw new Error("Not authenticated");
|
|
465
|
+
}
|
|
466
|
+
const response = await this.httpClient.post(`/api/v1/admin/activate-user/${userId}`, {});
|
|
467
|
+
return response;
|
|
468
|
+
}
|
|
303
469
|
};
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
RegisterForm: () => RegisterForm,
|
|
313
|
-
useAuth: () => useAuth
|
|
314
|
-
});
|
|
315
|
-
var useAuth = (config) => {
|
|
316
|
-
const [authService] = react.useState(() => new AuthService(config));
|
|
470
|
+
var AuthContext = react.createContext(void 0);
|
|
471
|
+
var AuthProvider = ({ children, config }) => {
|
|
472
|
+
const authConfig = {
|
|
473
|
+
baseUrl: config?.baseUrl || (typeof window !== "undefined" ? process.env.NEXT_PUBLIC_AUTH_API_URL || process.env.REACT_APP_AUTH_API_URL || "http://localhost:7000" : "http://localhost:7000"),
|
|
474
|
+
localStorageKey: config?.localStorageKey || "auth_token",
|
|
475
|
+
csrfEnabled: config?.csrfEnabled !== void 0 ? config.csrfEnabled : true
|
|
476
|
+
};
|
|
477
|
+
const [authService] = react.useState(() => new AuthService(authConfig));
|
|
317
478
|
const [user, setUser] = react.useState(null);
|
|
318
|
-
const [
|
|
319
|
-
const [loading, setLoading] = react.useState(
|
|
320
|
-
const checkAuthStatus = react.useCallback(() => {
|
|
479
|
+
const [isLoaded, setIsLoaded] = react.useState(false);
|
|
480
|
+
const [loading, setLoading] = react.useState(false);
|
|
481
|
+
const checkAuthStatus = react.useCallback(async () => {
|
|
321
482
|
const authenticated = authService.isAuthenticated();
|
|
322
|
-
setIsAuthenticated(authenticated);
|
|
323
483
|
if (authenticated) {
|
|
324
|
-
|
|
325
|
-
|
|
484
|
+
try {
|
|
485
|
+
const currentUser = authService.getCurrentUser();
|
|
486
|
+
setUser(currentUser);
|
|
487
|
+
} catch (error) {
|
|
488
|
+
console.error("Failed to get current user:", error);
|
|
489
|
+
setUser(null);
|
|
490
|
+
}
|
|
326
491
|
} else {
|
|
327
492
|
setUser(null);
|
|
328
493
|
}
|
|
329
|
-
|
|
494
|
+
setIsLoaded(true);
|
|
330
495
|
}, [authService]);
|
|
331
496
|
react.useEffect(() => {
|
|
332
497
|
checkAuthStatus();
|
|
333
498
|
}, [checkAuthStatus]);
|
|
334
|
-
const
|
|
499
|
+
const signIn = react.useCallback(async (data) => {
|
|
335
500
|
setLoading(true);
|
|
336
501
|
try {
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
339
|
-
|
|
502
|
+
const response = await authService.login(data);
|
|
503
|
+
if (response.success && response.user) {
|
|
504
|
+
setUser(response.user);
|
|
340
505
|
}
|
|
341
|
-
const response = await authService.register(registerData);
|
|
342
506
|
return response;
|
|
343
507
|
} finally {
|
|
344
508
|
setLoading(false);
|
|
345
509
|
}
|
|
346
510
|
}, [authService]);
|
|
347
|
-
const
|
|
511
|
+
const signUp = react.useCallback(async (data) => {
|
|
348
512
|
setLoading(true);
|
|
349
513
|
try {
|
|
350
|
-
const response = await authService.
|
|
351
|
-
if (response.success && response.user) {
|
|
352
|
-
setUser(response.user);
|
|
353
|
-
setIsAuthenticated(true);
|
|
354
|
-
}
|
|
514
|
+
const response = await authService.register(data);
|
|
355
515
|
return response;
|
|
356
516
|
} finally {
|
|
357
517
|
setLoading(false);
|
|
358
518
|
}
|
|
359
519
|
}, [authService]);
|
|
520
|
+
const signOut = react.useCallback(async () => {
|
|
521
|
+
setLoading(true);
|
|
522
|
+
try {
|
|
523
|
+
await authService.logout();
|
|
524
|
+
setUser(null);
|
|
525
|
+
} finally {
|
|
526
|
+
setLoading(false);
|
|
527
|
+
}
|
|
528
|
+
}, [authService]);
|
|
360
529
|
const verify = react.useCallback(async (data) => {
|
|
361
530
|
setLoading(true);
|
|
362
531
|
try {
|
|
363
532
|
const response = await authService.verify(data);
|
|
364
533
|
if (response.success && response.user) {
|
|
365
534
|
setUser(response.user);
|
|
366
|
-
setIsAuthenticated(true);
|
|
367
535
|
}
|
|
368
536
|
return response;
|
|
369
537
|
} finally {
|
|
@@ -376,23 +544,12 @@ var useAuth = (config) => {
|
|
|
376
544
|
const response = await authService.verifyEmailToken(token);
|
|
377
545
|
if (response.success && response.user) {
|
|
378
546
|
setUser(response.user);
|
|
379
|
-
setIsAuthenticated(true);
|
|
380
547
|
}
|
|
381
548
|
return response;
|
|
382
549
|
} finally {
|
|
383
550
|
setLoading(false);
|
|
384
551
|
}
|
|
385
552
|
}, [authService]);
|
|
386
|
-
const logout = react.useCallback(async () => {
|
|
387
|
-
setLoading(true);
|
|
388
|
-
try {
|
|
389
|
-
await authService.logout();
|
|
390
|
-
setUser(null);
|
|
391
|
-
setIsAuthenticated(false);
|
|
392
|
-
} finally {
|
|
393
|
-
setLoading(false);
|
|
394
|
-
}
|
|
395
|
-
}, [authService]);
|
|
396
553
|
const updateProfile = react.useCallback(async (data) => {
|
|
397
554
|
setLoading(true);
|
|
398
555
|
try {
|
|
@@ -415,90 +572,356 @@ var useAuth = (config) => {
|
|
|
415
572
|
setLoading(false);
|
|
416
573
|
}
|
|
417
574
|
}, [authService]);
|
|
418
|
-
const
|
|
575
|
+
const signInWithOAuth = react.useCallback((provider) => {
|
|
576
|
+
authService.loginWithOAuth(provider);
|
|
577
|
+
}, [authService]);
|
|
578
|
+
const linkOAuthProvider = react.useCallback((provider) => {
|
|
579
|
+
authService.linkOAuthProvider(provider);
|
|
580
|
+
}, [authService]);
|
|
581
|
+
const unlinkOAuthProvider = react.useCallback(async (provider) => {
|
|
419
582
|
setLoading(true);
|
|
420
583
|
try {
|
|
421
|
-
return await authService.
|
|
584
|
+
return await authService.unlinkOAuthProvider(provider);
|
|
422
585
|
} finally {
|
|
423
586
|
setLoading(false);
|
|
424
587
|
}
|
|
425
588
|
}, [authService]);
|
|
426
|
-
const
|
|
589
|
+
const forgotPassword = react.useCallback(async (email) => {
|
|
427
590
|
setLoading(true);
|
|
428
591
|
try {
|
|
429
|
-
return await authService.
|
|
592
|
+
return await authService.forgotPassword(email);
|
|
430
593
|
} finally {
|
|
431
594
|
setLoading(false);
|
|
432
595
|
}
|
|
433
596
|
}, [authService]);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
isAuthenticated,
|
|
437
|
-
loading,
|
|
438
|
-
register,
|
|
439
|
-
login,
|
|
440
|
-
verify,
|
|
441
|
-
verifyEmailToken,
|
|
442
|
-
logout,
|
|
443
|
-
updateProfile,
|
|
444
|
-
getProfile,
|
|
445
|
-
getAllUsers,
|
|
446
|
-
getUserById
|
|
447
|
-
};
|
|
448
|
-
};
|
|
449
|
-
var LoginForm = ({
|
|
450
|
-
onSuccess,
|
|
451
|
-
onLoginSuccess,
|
|
452
|
-
onRegisterClick,
|
|
453
|
-
showRegisterLink = true,
|
|
454
|
-
config,
|
|
455
|
-
oauthProviders = ["google", "github"],
|
|
456
|
-
showOAuthButtons = true
|
|
457
|
-
}) => {
|
|
458
|
-
const [email, setEmail] = react.useState("");
|
|
459
|
-
const [password, setPassword] = react.useState("");
|
|
460
|
-
const [usePassword, setUsePassword] = react.useState(false);
|
|
461
|
-
const [showPassword, setShowPassword] = react.useState(false);
|
|
462
|
-
const [isLoading, setIsLoading] = react.useState(false);
|
|
463
|
-
const [error, setError] = react.useState(null);
|
|
464
|
-
const [rememberMe, setRememberMe] = react.useState(false);
|
|
465
|
-
const { login } = useAuth({
|
|
466
|
-
baseUrl: config?.baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
|
|
467
|
-
});
|
|
468
|
-
const handleSubmit = async (e) => {
|
|
469
|
-
e.preventDefault();
|
|
470
|
-
setIsLoading(true);
|
|
471
|
-
setError(null);
|
|
597
|
+
const resetPassword = react.useCallback(async (token, password) => {
|
|
598
|
+
setLoading(true);
|
|
472
599
|
try {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
600
|
+
return await authService.resetPassword(token, password);
|
|
601
|
+
} finally {
|
|
602
|
+
setLoading(false);
|
|
603
|
+
}
|
|
604
|
+
}, [authService]);
|
|
605
|
+
const changePassword = react.useCallback(async (oldPassword, newPassword) => {
|
|
606
|
+
setLoading(true);
|
|
607
|
+
try {
|
|
608
|
+
return await authService.changePassword(oldPassword, newPassword);
|
|
609
|
+
} finally {
|
|
610
|
+
setLoading(false);
|
|
611
|
+
}
|
|
612
|
+
}, [authService]);
|
|
613
|
+
const updateAvatar = react.useCallback(async (avatar) => {
|
|
614
|
+
setLoading(true);
|
|
615
|
+
try {
|
|
616
|
+
const response = await authService.updateAvatar(avatar);
|
|
617
|
+
if (response.success && response.user) {
|
|
618
|
+
setUser(response.user);
|
|
492
619
|
}
|
|
493
|
-
|
|
494
|
-
setError(err instanceof Error ? err.message : "An unknown error occurred");
|
|
620
|
+
return response;
|
|
495
621
|
} finally {
|
|
496
|
-
|
|
622
|
+
setLoading(false);
|
|
497
623
|
}
|
|
498
|
-
};
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
624
|
+
}, [authService]);
|
|
625
|
+
const requestEmailChange = react.useCallback(async (newEmail) => {
|
|
626
|
+
setLoading(true);
|
|
627
|
+
try {
|
|
628
|
+
return await authService.requestEmailChange(newEmail);
|
|
629
|
+
} finally {
|
|
630
|
+
setLoading(false);
|
|
631
|
+
}
|
|
632
|
+
}, [authService]);
|
|
633
|
+
const verifyEmailChange = react.useCallback(async (token) => {
|
|
634
|
+
setLoading(true);
|
|
635
|
+
try {
|
|
636
|
+
const response = await authService.verifyEmailChange(token);
|
|
637
|
+
if (response.success && response.user) {
|
|
638
|
+
setUser(response.user);
|
|
639
|
+
}
|
|
640
|
+
return response;
|
|
641
|
+
} finally {
|
|
642
|
+
setLoading(false);
|
|
643
|
+
}
|
|
644
|
+
}, [authService]);
|
|
645
|
+
const generate2FA = react.useCallback(async () => {
|
|
646
|
+
setLoading(true);
|
|
647
|
+
try {
|
|
648
|
+
return await authService.generate2FA();
|
|
649
|
+
} finally {
|
|
650
|
+
setLoading(false);
|
|
651
|
+
}
|
|
652
|
+
}, [authService]);
|
|
653
|
+
const enable2FA = react.useCallback(async (token) => {
|
|
654
|
+
setLoading(true);
|
|
655
|
+
try {
|
|
656
|
+
return await authService.enable2FA(token);
|
|
657
|
+
} finally {
|
|
658
|
+
setLoading(false);
|
|
659
|
+
}
|
|
660
|
+
}, [authService]);
|
|
661
|
+
const disable2FA = react.useCallback(async (token) => {
|
|
662
|
+
setLoading(true);
|
|
663
|
+
try {
|
|
664
|
+
return await authService.disable2FA(token);
|
|
665
|
+
} finally {
|
|
666
|
+
setLoading(false);
|
|
667
|
+
}
|
|
668
|
+
}, [authService]);
|
|
669
|
+
const validate2FA = react.useCallback(async (token) => {
|
|
670
|
+
setLoading(true);
|
|
671
|
+
try {
|
|
672
|
+
return await authService.validate2FA(token);
|
|
673
|
+
} finally {
|
|
674
|
+
setLoading(false);
|
|
675
|
+
}
|
|
676
|
+
}, [authService]);
|
|
677
|
+
const getSessions = react.useCallback(async () => {
|
|
678
|
+
setLoading(true);
|
|
679
|
+
try {
|
|
680
|
+
return await authService.getSessions();
|
|
681
|
+
} finally {
|
|
682
|
+
setLoading(false);
|
|
683
|
+
}
|
|
684
|
+
}, [authService]);
|
|
685
|
+
const revokeSession = react.useCallback(async (sessionId) => {
|
|
686
|
+
setLoading(true);
|
|
687
|
+
try {
|
|
688
|
+
return await authService.revokeSession(sessionId);
|
|
689
|
+
} finally {
|
|
690
|
+
setLoading(false);
|
|
691
|
+
}
|
|
692
|
+
}, [authService]);
|
|
693
|
+
const revokeAllSessions = react.useCallback(async () => {
|
|
694
|
+
setLoading(true);
|
|
695
|
+
try {
|
|
696
|
+
const response = await authService.revokeAllSessions();
|
|
697
|
+
setUser(null);
|
|
698
|
+
return response;
|
|
699
|
+
} finally {
|
|
700
|
+
setLoading(false);
|
|
701
|
+
}
|
|
702
|
+
}, [authService]);
|
|
703
|
+
const value = {
|
|
704
|
+
user,
|
|
705
|
+
isLoaded,
|
|
706
|
+
isSignedIn: !!user,
|
|
707
|
+
loading,
|
|
708
|
+
signIn,
|
|
709
|
+
signUp,
|
|
710
|
+
signOut,
|
|
711
|
+
verify,
|
|
712
|
+
verifyEmailToken,
|
|
713
|
+
updateProfile,
|
|
714
|
+
getProfile,
|
|
715
|
+
signInWithOAuth,
|
|
716
|
+
linkOAuthProvider,
|
|
717
|
+
unlinkOAuthProvider,
|
|
718
|
+
forgotPassword,
|
|
719
|
+
resetPassword,
|
|
720
|
+
changePassword,
|
|
721
|
+
updateAvatar,
|
|
722
|
+
requestEmailChange,
|
|
723
|
+
verifyEmailChange,
|
|
724
|
+
generate2FA,
|
|
725
|
+
enable2FA,
|
|
726
|
+
disable2FA,
|
|
727
|
+
validate2FA,
|
|
728
|
+
getSessions,
|
|
729
|
+
revokeSession,
|
|
730
|
+
revokeAllSessions,
|
|
731
|
+
authService
|
|
732
|
+
};
|
|
733
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children });
|
|
734
|
+
};
|
|
735
|
+
var useAuth = () => {
|
|
736
|
+
const context = react.useContext(AuthContext);
|
|
737
|
+
if (context === void 0) {
|
|
738
|
+
throw new Error("useAuth must be used within an AuthProvider");
|
|
739
|
+
}
|
|
740
|
+
return context;
|
|
741
|
+
};
|
|
742
|
+
var useAuth2 = (config) => {
|
|
743
|
+
const [authService] = react.useState(() => new AuthService(config));
|
|
744
|
+
const [user, setUser] = react.useState(null);
|
|
745
|
+
const [isAuthenticated, setIsAuthenticated] = react.useState(false);
|
|
746
|
+
const [loading, setLoading] = react.useState(true);
|
|
747
|
+
const checkAuthStatus = react.useCallback(() => {
|
|
748
|
+
const authenticated = authService.isAuthenticated();
|
|
749
|
+
setIsAuthenticated(authenticated);
|
|
750
|
+
if (authenticated) {
|
|
751
|
+
const currentUser = authService.getCurrentUser();
|
|
752
|
+
setUser(currentUser);
|
|
753
|
+
} else {
|
|
754
|
+
setUser(null);
|
|
755
|
+
}
|
|
756
|
+
setLoading(false);
|
|
757
|
+
}, [authService]);
|
|
758
|
+
react.useEffect(() => {
|
|
759
|
+
checkAuthStatus();
|
|
760
|
+
}, [checkAuthStatus]);
|
|
761
|
+
const register = react.useCallback(async (data) => {
|
|
762
|
+
setLoading(true);
|
|
763
|
+
try {
|
|
764
|
+
const response = await authService.register(data);
|
|
765
|
+
return response;
|
|
766
|
+
} finally {
|
|
767
|
+
setLoading(false);
|
|
768
|
+
}
|
|
769
|
+
}, [authService]);
|
|
770
|
+
const login = react.useCallback(async (data) => {
|
|
771
|
+
setLoading(true);
|
|
772
|
+
try {
|
|
773
|
+
const response = await authService.login(data);
|
|
774
|
+
if (response.success && response.user) {
|
|
775
|
+
setUser(response.user);
|
|
776
|
+
setIsAuthenticated(true);
|
|
777
|
+
}
|
|
778
|
+
return response;
|
|
779
|
+
} finally {
|
|
780
|
+
setLoading(false);
|
|
781
|
+
}
|
|
782
|
+
}, [authService]);
|
|
783
|
+
const verify = react.useCallback(async (data) => {
|
|
784
|
+
setLoading(true);
|
|
785
|
+
try {
|
|
786
|
+
const response = await authService.verify(data);
|
|
787
|
+
if (response.success && response.user) {
|
|
788
|
+
setUser(response.user);
|
|
789
|
+
setIsAuthenticated(true);
|
|
790
|
+
}
|
|
791
|
+
return response;
|
|
792
|
+
} finally {
|
|
793
|
+
setLoading(false);
|
|
794
|
+
}
|
|
795
|
+
}, [authService]);
|
|
796
|
+
const verifyEmailToken = react.useCallback(async (token) => {
|
|
797
|
+
setLoading(true);
|
|
798
|
+
try {
|
|
799
|
+
const response = await authService.verifyEmailToken(token);
|
|
800
|
+
if (response.success && response.user) {
|
|
801
|
+
setUser(response.user);
|
|
802
|
+
setIsAuthenticated(true);
|
|
803
|
+
}
|
|
804
|
+
return response;
|
|
805
|
+
} finally {
|
|
806
|
+
setLoading(false);
|
|
807
|
+
}
|
|
808
|
+
}, [authService]);
|
|
809
|
+
const logout = react.useCallback(async () => {
|
|
810
|
+
setLoading(true);
|
|
811
|
+
try {
|
|
812
|
+
await authService.logout();
|
|
813
|
+
setUser(null);
|
|
814
|
+
setIsAuthenticated(false);
|
|
815
|
+
} finally {
|
|
816
|
+
setLoading(false);
|
|
817
|
+
}
|
|
818
|
+
}, [authService]);
|
|
819
|
+
const updateProfile = react.useCallback(async (data) => {
|
|
820
|
+
setLoading(true);
|
|
821
|
+
try {
|
|
822
|
+
const response = await authService.updateProfile(data);
|
|
823
|
+
if (response.success && response.user) {
|
|
824
|
+
setUser(response.user);
|
|
825
|
+
}
|
|
826
|
+
return response;
|
|
827
|
+
} finally {
|
|
828
|
+
setLoading(false);
|
|
829
|
+
}
|
|
830
|
+
}, [authService]);
|
|
831
|
+
const getProfile = react.useCallback(async () => {
|
|
832
|
+
setLoading(true);
|
|
833
|
+
try {
|
|
834
|
+
const userData = await authService.getProfile();
|
|
835
|
+
setUser(userData);
|
|
836
|
+
return userData;
|
|
837
|
+
} finally {
|
|
838
|
+
setLoading(false);
|
|
839
|
+
}
|
|
840
|
+
}, [authService]);
|
|
841
|
+
const getAllUsers = react.useCallback(async () => {
|
|
842
|
+
setLoading(true);
|
|
843
|
+
try {
|
|
844
|
+
return await authService.getAllUsers();
|
|
845
|
+
} finally {
|
|
846
|
+
setLoading(false);
|
|
847
|
+
}
|
|
848
|
+
}, [authService]);
|
|
849
|
+
const getUserById = react.useCallback(async (id) => {
|
|
850
|
+
setLoading(true);
|
|
851
|
+
try {
|
|
852
|
+
return await authService.getUserById(id);
|
|
853
|
+
} finally {
|
|
854
|
+
setLoading(false);
|
|
855
|
+
}
|
|
856
|
+
}, [authService]);
|
|
857
|
+
return {
|
|
858
|
+
user,
|
|
859
|
+
isAuthenticated,
|
|
860
|
+
loading,
|
|
861
|
+
register,
|
|
862
|
+
login,
|
|
863
|
+
verify,
|
|
864
|
+
verifyEmailToken,
|
|
865
|
+
logout,
|
|
866
|
+
updateProfile,
|
|
867
|
+
getProfile,
|
|
868
|
+
getAllUsers,
|
|
869
|
+
getUserById
|
|
870
|
+
};
|
|
871
|
+
};
|
|
872
|
+
var LoginForm = ({
|
|
873
|
+
onSuccess,
|
|
874
|
+
onLoginSuccess,
|
|
875
|
+
onRegisterClick,
|
|
876
|
+
showRegisterLink = true,
|
|
877
|
+
config,
|
|
878
|
+
oauthProviders = ["google", "github"],
|
|
879
|
+
showOAuthButtons = true
|
|
880
|
+
}) => {
|
|
881
|
+
const [email, setEmail] = react.useState("");
|
|
882
|
+
const [password, setPassword] = react.useState("");
|
|
883
|
+
const [usePassword, setUsePassword] = react.useState(false);
|
|
884
|
+
const [showPassword, setShowPassword] = react.useState(false);
|
|
885
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
886
|
+
const [error, setError] = react.useState(null);
|
|
887
|
+
const [rememberMe, setRememberMe] = react.useState(false);
|
|
888
|
+
const { login } = useAuth2({
|
|
889
|
+
baseUrl: config?.baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
|
|
890
|
+
});
|
|
891
|
+
const handleSubmit = async (e) => {
|
|
892
|
+
e.preventDefault();
|
|
893
|
+
setIsLoading(true);
|
|
894
|
+
setError(null);
|
|
895
|
+
try {
|
|
896
|
+
let response;
|
|
897
|
+
if (usePassword) {
|
|
898
|
+
response = await login({ email, password });
|
|
899
|
+
} else {
|
|
900
|
+
response = await login({ email });
|
|
901
|
+
}
|
|
902
|
+
if (response.success) {
|
|
903
|
+
onSuccess?.(response);
|
|
904
|
+
if (onLoginSuccess) {
|
|
905
|
+
if (response.message === "OTP sent to your email.") {
|
|
906
|
+
onLoginSuccess(email, true);
|
|
907
|
+
} else if (response.token) {
|
|
908
|
+
onLoginSuccess(email, false);
|
|
909
|
+
} else {
|
|
910
|
+
onLoginSuccess(email, true);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
} else {
|
|
914
|
+
setError(response.message || "Login failed");
|
|
915
|
+
}
|
|
916
|
+
} catch (err) {
|
|
917
|
+
setError(err instanceof Error ? err.message : "An unknown error occurred");
|
|
918
|
+
} finally {
|
|
919
|
+
setIsLoading(false);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
const toggleAuthMethod = () => {
|
|
923
|
+
setUsePassword(!usePassword);
|
|
924
|
+
setError(null);
|
|
502
925
|
};
|
|
503
926
|
const togglePasswordVisibility = () => {
|
|
504
927
|
setShowPassword(!showPassword);
|
|
@@ -906,7 +1329,7 @@ var RegisterForm = ({
|
|
|
906
1329
|
const config = authConfig || {
|
|
907
1330
|
baseUrl: typeof window !== "undefined" ? process.env.NEXT_PUBLIC_AUTH_API_URL || window.location.origin : "http://localhost:7000"
|
|
908
1331
|
};
|
|
909
|
-
const { register } =
|
|
1332
|
+
const { register } = useAuth2(config);
|
|
910
1333
|
const handleSubmit = async (e) => {
|
|
911
1334
|
e.preventDefault();
|
|
912
1335
|
setIsLoading(true);
|
|
@@ -1301,7 +1724,7 @@ var OtpForm = ({
|
|
|
1301
1724
|
const [error, setError] = react.useState(null);
|
|
1302
1725
|
const [resendCooldown, setResendCooldown] = react.useState(0);
|
|
1303
1726
|
const [resendLoading, setResendLoading] = react.useState(false);
|
|
1304
|
-
const { verify, login } =
|
|
1727
|
+
const { verify, login } = useAuth2({
|
|
1305
1728
|
baseUrl: typeof window !== "undefined" ? window.location.origin : "http://localhost:7000"
|
|
1306
1729
|
});
|
|
1307
1730
|
const handleSubmit = async (e) => {
|
|
@@ -1652,7 +2075,7 @@ var EmailVerificationPage = ({
|
|
|
1652
2075
|
const [isLoading, setIsLoading] = react.useState(true);
|
|
1653
2076
|
const [message, setMessage] = react.useState("");
|
|
1654
2077
|
const [isSuccess, setIsSuccess] = react.useState(false);
|
|
1655
|
-
const { verifyEmailToken } =
|
|
2078
|
+
const { verifyEmailToken } = useAuth2({
|
|
1656
2079
|
baseUrl: baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
|
|
1657
2080
|
});
|
|
1658
2081
|
react.useEffect(() => {
|
|
@@ -1760,6 +2183,1825 @@ var EmailVerificationPage = ({
|
|
|
1760
2183
|
] })
|
|
1761
2184
|
] }) });
|
|
1762
2185
|
};
|
|
2186
|
+
var SignIn = ({ redirectUrl, appearance }) => {
|
|
2187
|
+
const { signIn, isSignedIn, loading: authLoading } = useAuth();
|
|
2188
|
+
const [email, setEmail] = react.useState("");
|
|
2189
|
+
const [password, setPassword] = react.useState("");
|
|
2190
|
+
const [otp, setOtp] = react.useState("");
|
|
2191
|
+
const [usePassword, setUsePassword] = react.useState(false);
|
|
2192
|
+
const [showPassword, setShowPassword] = react.useState(false);
|
|
2193
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
2194
|
+
const [error, setError] = react.useState(null);
|
|
2195
|
+
const [needsOtp, setNeedsOtp] = react.useState(false);
|
|
2196
|
+
const [success, setSuccess] = react.useState(null);
|
|
2197
|
+
react.useEffect(() => {
|
|
2198
|
+
if (isSignedIn && redirectUrl) {
|
|
2199
|
+
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
2200
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
2201
|
+
window.location.href = `${baseUrl}${redirect}`;
|
|
2202
|
+
}
|
|
2203
|
+
}, [isSignedIn, redirectUrl]);
|
|
2204
|
+
const handleSubmit = async (e) => {
|
|
2205
|
+
e.preventDefault();
|
|
2206
|
+
setIsLoading(true);
|
|
2207
|
+
setError(null);
|
|
2208
|
+
setSuccess(null);
|
|
2209
|
+
try {
|
|
2210
|
+
if (needsOtp) {
|
|
2211
|
+
const response = await signIn({ email, otp });
|
|
2212
|
+
if (response.success) {
|
|
2213
|
+
setSuccess("Login successful!");
|
|
2214
|
+
} else {
|
|
2215
|
+
setError(response.message || "OTP verification failed");
|
|
2216
|
+
}
|
|
2217
|
+
} else if (usePassword) {
|
|
2218
|
+
const response = await signIn({ email, password });
|
|
2219
|
+
if (response.success) {
|
|
2220
|
+
setSuccess("Login successful!");
|
|
2221
|
+
} else {
|
|
2222
|
+
setError(response.message || "Login failed");
|
|
2223
|
+
}
|
|
2224
|
+
} else {
|
|
2225
|
+
const response = await signIn({ email });
|
|
2226
|
+
if (response.success && response.message === "OTP sent to your email.") {
|
|
2227
|
+
setNeedsOtp(true);
|
|
2228
|
+
setSuccess("OTP sent to your email. Please check your inbox.");
|
|
2229
|
+
} else {
|
|
2230
|
+
setError(response.message || "Failed to send OTP");
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
} catch (err) {
|
|
2234
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
2235
|
+
} finally {
|
|
2236
|
+
setIsLoading(false);
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
const toggleAuthMethod = () => {
|
|
2240
|
+
setUsePassword(!usePassword);
|
|
2241
|
+
setNeedsOtp(false);
|
|
2242
|
+
setError(null);
|
|
2243
|
+
setSuccess(null);
|
|
2244
|
+
setOtp("");
|
|
2245
|
+
};
|
|
2246
|
+
if (authLoading) {
|
|
2247
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }) });
|
|
2248
|
+
}
|
|
2249
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2250
|
+
maxWidth: "400px",
|
|
2251
|
+
margin: "0 auto",
|
|
2252
|
+
padding: "30px",
|
|
2253
|
+
borderRadius: "12px",
|
|
2254
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
2255
|
+
backgroundColor: "#ffffff",
|
|
2256
|
+
border: "1px solid #eaeaea",
|
|
2257
|
+
...appearance?.elements?.card
|
|
2258
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
|
|
2259
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
2260
|
+
textAlign: "center",
|
|
2261
|
+
marginBottom: "24px",
|
|
2262
|
+
color: "#1f2937",
|
|
2263
|
+
fontSize: "24px",
|
|
2264
|
+
fontWeight: 600,
|
|
2265
|
+
...appearance?.elements?.headerTitle
|
|
2266
|
+
}, children: needsOtp ? "Enter OTP" : usePassword ? "Sign in with password" : "Sign in" }),
|
|
2267
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2268
|
+
padding: "12px 16px",
|
|
2269
|
+
marginBottom: "20px",
|
|
2270
|
+
backgroundColor: "#fee",
|
|
2271
|
+
color: "#c33",
|
|
2272
|
+
border: "1px solid #fcc",
|
|
2273
|
+
borderRadius: "8px",
|
|
2274
|
+
fontSize: "14px"
|
|
2275
|
+
}, children: error }),
|
|
2276
|
+
success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2277
|
+
padding: "12px 16px",
|
|
2278
|
+
marginBottom: "20px",
|
|
2279
|
+
backgroundColor: "#efe",
|
|
2280
|
+
color: "#3c3",
|
|
2281
|
+
border: "1px solid #cfc",
|
|
2282
|
+
borderRadius: "8px",
|
|
2283
|
+
fontSize: "14px"
|
|
2284
|
+
}, children: success }),
|
|
2285
|
+
!needsOtp && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
2286
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
|
|
2287
|
+
display: "block",
|
|
2288
|
+
marginBottom: "8px",
|
|
2289
|
+
fontWeight: 500,
|
|
2290
|
+
color: "#374151",
|
|
2291
|
+
fontSize: "14px"
|
|
2292
|
+
}, children: "Email" }),
|
|
2293
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2294
|
+
"input",
|
|
2295
|
+
{
|
|
2296
|
+
id: "email",
|
|
2297
|
+
type: "email",
|
|
2298
|
+
value: email,
|
|
2299
|
+
onChange: (e) => setEmail(e.target.value),
|
|
2300
|
+
required: true,
|
|
2301
|
+
disabled: isLoading,
|
|
2302
|
+
style: {
|
|
2303
|
+
width: "100%",
|
|
2304
|
+
padding: "12px 16px",
|
|
2305
|
+
border: "1px solid #ddd",
|
|
2306
|
+
borderRadius: "8px",
|
|
2307
|
+
fontSize: "16px",
|
|
2308
|
+
boxSizing: "border-box",
|
|
2309
|
+
...appearance?.elements?.formFieldInput
|
|
2310
|
+
},
|
|
2311
|
+
placeholder: "Enter your email"
|
|
2312
|
+
}
|
|
2313
|
+
)
|
|
2314
|
+
] }),
|
|
2315
|
+
usePassword && !needsOtp && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
|
|
2316
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
|
|
2317
|
+
display: "block",
|
|
2318
|
+
marginBottom: "8px",
|
|
2319
|
+
fontWeight: 500,
|
|
2320
|
+
color: "#374151",
|
|
2321
|
+
fontSize: "14px"
|
|
2322
|
+
}, children: "Password" }),
|
|
2323
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2324
|
+
"input",
|
|
2325
|
+
{
|
|
2326
|
+
id: "password",
|
|
2327
|
+
type: showPassword ? "text" : "password",
|
|
2328
|
+
value: password,
|
|
2329
|
+
onChange: (e) => setPassword(e.target.value),
|
|
2330
|
+
required: true,
|
|
2331
|
+
disabled: isLoading,
|
|
2332
|
+
style: {
|
|
2333
|
+
width: "100%",
|
|
2334
|
+
padding: "12px 16px",
|
|
2335
|
+
border: "1px solid #ddd",
|
|
2336
|
+
borderRadius: "8px",
|
|
2337
|
+
fontSize: "16px",
|
|
2338
|
+
boxSizing: "border-box",
|
|
2339
|
+
...appearance?.elements?.formFieldInput
|
|
2340
|
+
},
|
|
2341
|
+
placeholder: "Enter your password"
|
|
2342
|
+
}
|
|
2343
|
+
),
|
|
2344
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2345
|
+
"button",
|
|
2346
|
+
{
|
|
2347
|
+
type: "button",
|
|
2348
|
+
onClick: () => setShowPassword(!showPassword),
|
|
2349
|
+
style: {
|
|
2350
|
+
position: "absolute",
|
|
2351
|
+
right: "12px",
|
|
2352
|
+
top: "38px",
|
|
2353
|
+
background: "none",
|
|
2354
|
+
border: "none",
|
|
2355
|
+
cursor: "pointer",
|
|
2356
|
+
color: "#666",
|
|
2357
|
+
fontSize: "14px"
|
|
2358
|
+
},
|
|
2359
|
+
children: showPassword ? "Hide" : "Show"
|
|
2360
|
+
}
|
|
2361
|
+
)
|
|
2362
|
+
] }),
|
|
2363
|
+
needsOtp && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
2364
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "otp", style: {
|
|
2365
|
+
display: "block",
|
|
2366
|
+
marginBottom: "8px",
|
|
2367
|
+
fontWeight: 500,
|
|
2368
|
+
color: "#374151",
|
|
2369
|
+
fontSize: "14px"
|
|
2370
|
+
}, children: "One-Time Password" }),
|
|
2371
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2372
|
+
"input",
|
|
2373
|
+
{
|
|
2374
|
+
id: "otp",
|
|
2375
|
+
type: "text",
|
|
2376
|
+
value: otp,
|
|
2377
|
+
onChange: (e) => setOtp(e.target.value),
|
|
2378
|
+
required: true,
|
|
2379
|
+
disabled: isLoading,
|
|
2380
|
+
maxLength: 6,
|
|
2381
|
+
style: {
|
|
2382
|
+
width: "100%",
|
|
2383
|
+
padding: "12px 16px",
|
|
2384
|
+
border: "1px solid #ddd",
|
|
2385
|
+
borderRadius: "8px",
|
|
2386
|
+
fontSize: "16px",
|
|
2387
|
+
boxSizing: "border-box",
|
|
2388
|
+
letterSpacing: "0.5em",
|
|
2389
|
+
textAlign: "center",
|
|
2390
|
+
...appearance?.elements?.formFieldInput
|
|
2391
|
+
},
|
|
2392
|
+
placeholder: "000000"
|
|
2393
|
+
}
|
|
2394
|
+
)
|
|
2395
|
+
] }),
|
|
2396
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2397
|
+
"button",
|
|
2398
|
+
{
|
|
2399
|
+
type: "submit",
|
|
2400
|
+
disabled: isLoading,
|
|
2401
|
+
style: {
|
|
2402
|
+
width: "100%",
|
|
2403
|
+
padding: "14px",
|
|
2404
|
+
backgroundColor: "#007bff",
|
|
2405
|
+
color: "white",
|
|
2406
|
+
border: "none",
|
|
2407
|
+
borderRadius: "8px",
|
|
2408
|
+
fontSize: "16px",
|
|
2409
|
+
fontWeight: 600,
|
|
2410
|
+
cursor: "pointer",
|
|
2411
|
+
transition: "all 0.2s ease",
|
|
2412
|
+
...appearance?.elements?.formButtonPrimary
|
|
2413
|
+
},
|
|
2414
|
+
children: isLoading ? "Please wait..." : needsOtp ? "Verify OTP" : usePassword ? "Sign in" : "Continue with email"
|
|
2415
|
+
}
|
|
2416
|
+
),
|
|
2417
|
+
!needsOtp && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", marginTop: "16px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2418
|
+
"button",
|
|
2419
|
+
{
|
|
2420
|
+
type: "button",
|
|
2421
|
+
onClick: toggleAuthMethod,
|
|
2422
|
+
disabled: isLoading,
|
|
2423
|
+
style: {
|
|
2424
|
+
background: "none",
|
|
2425
|
+
border: "none",
|
|
2426
|
+
color: "#007bff",
|
|
2427
|
+
cursor: "pointer",
|
|
2428
|
+
fontSize: "14px",
|
|
2429
|
+
fontWeight: 600
|
|
2430
|
+
},
|
|
2431
|
+
children: usePassword ? "Use email code instead" : "Use password instead"
|
|
2432
|
+
}
|
|
2433
|
+
) }),
|
|
2434
|
+
needsOtp && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", marginTop: "16px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2435
|
+
"button",
|
|
2436
|
+
{
|
|
2437
|
+
type: "button",
|
|
2438
|
+
onClick: () => {
|
|
2439
|
+
setNeedsOtp(false);
|
|
2440
|
+
setOtp("");
|
|
2441
|
+
setError(null);
|
|
2442
|
+
setSuccess(null);
|
|
2443
|
+
},
|
|
2444
|
+
disabled: isLoading,
|
|
2445
|
+
style: {
|
|
2446
|
+
background: "none",
|
|
2447
|
+
border: "none",
|
|
2448
|
+
color: "#007bff",
|
|
2449
|
+
cursor: "pointer",
|
|
2450
|
+
fontSize: "14px",
|
|
2451
|
+
fontWeight: 600
|
|
2452
|
+
},
|
|
2453
|
+
children: "Back to sign in"
|
|
2454
|
+
}
|
|
2455
|
+
) })
|
|
2456
|
+
] }) });
|
|
2457
|
+
};
|
|
2458
|
+
var SignUp = ({ redirectUrl, appearance }) => {
|
|
2459
|
+
const { signUp, isSignedIn } = useAuth();
|
|
2460
|
+
const [name, setName] = react.useState("");
|
|
2461
|
+
const [email, setEmail] = react.useState("");
|
|
2462
|
+
const [password, setPassword] = react.useState("");
|
|
2463
|
+
const [confirmPassword, setConfirmPassword] = react.useState("");
|
|
2464
|
+
const [showPassword, setShowPassword] = react.useState(false);
|
|
2465
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
2466
|
+
const [error, setError] = react.useState(null);
|
|
2467
|
+
const [success, setSuccess] = react.useState(null);
|
|
2468
|
+
react.useEffect(() => {
|
|
2469
|
+
if (isSignedIn && redirectUrl) {
|
|
2470
|
+
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_AFTER_REGISTER || "/dashboard";
|
|
2471
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
2472
|
+
window.location.href = `${baseUrl}${redirect}`;
|
|
2473
|
+
}
|
|
2474
|
+
}, [isSignedIn, redirectUrl]);
|
|
2475
|
+
const getPasswordStrength = (pwd) => {
|
|
2476
|
+
if (!pwd)
|
|
2477
|
+
return { strength: "weak", color: "#ddd" };
|
|
2478
|
+
let score = 0;
|
|
2479
|
+
if (pwd.length >= 6)
|
|
2480
|
+
score++;
|
|
2481
|
+
if (pwd.length >= 8)
|
|
2482
|
+
score++;
|
|
2483
|
+
if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
|
|
2484
|
+
score++;
|
|
2485
|
+
if (/\d/.test(pwd))
|
|
2486
|
+
score++;
|
|
2487
|
+
if (/[^a-zA-Z\d]/.test(pwd))
|
|
2488
|
+
score++;
|
|
2489
|
+
if (score <= 2)
|
|
2490
|
+
return { strength: "weak", color: "#f44" };
|
|
2491
|
+
if (score <= 3)
|
|
2492
|
+
return { strength: "medium", color: "#fa4" };
|
|
2493
|
+
return { strength: "strong", color: "#4f4" };
|
|
2494
|
+
};
|
|
2495
|
+
const passwordStrength = getPasswordStrength(password);
|
|
2496
|
+
const handleSubmit = async (e) => {
|
|
2497
|
+
e.preventDefault();
|
|
2498
|
+
setIsLoading(true);
|
|
2499
|
+
setError(null);
|
|
2500
|
+
setSuccess(null);
|
|
2501
|
+
if (password !== confirmPassword) {
|
|
2502
|
+
setError("Passwords do not match");
|
|
2503
|
+
setIsLoading(false);
|
|
2504
|
+
return;
|
|
2505
|
+
}
|
|
2506
|
+
if (password.length < 6) {
|
|
2507
|
+
setError("Password must be at least 6 characters");
|
|
2508
|
+
setIsLoading(false);
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
try {
|
|
2512
|
+
const response = await signUp({ name, email, password });
|
|
2513
|
+
if (response.success) {
|
|
2514
|
+
setSuccess("Registration successful! Please check your email to verify your account.");
|
|
2515
|
+
} else {
|
|
2516
|
+
setError(response.message || "Registration failed");
|
|
2517
|
+
}
|
|
2518
|
+
} catch (err) {
|
|
2519
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
2520
|
+
} finally {
|
|
2521
|
+
setIsLoading(false);
|
|
2522
|
+
}
|
|
2523
|
+
};
|
|
2524
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2525
|
+
maxWidth: "400px",
|
|
2526
|
+
margin: "0 auto",
|
|
2527
|
+
padding: "30px",
|
|
2528
|
+
borderRadius: "12px",
|
|
2529
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
2530
|
+
backgroundColor: "#ffffff",
|
|
2531
|
+
border: "1px solid #eaeaea",
|
|
2532
|
+
...appearance?.elements?.card
|
|
2533
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
|
|
2534
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
2535
|
+
textAlign: "center",
|
|
2536
|
+
marginBottom: "24px",
|
|
2537
|
+
color: "#1f2937",
|
|
2538
|
+
fontSize: "24px",
|
|
2539
|
+
fontWeight: 600,
|
|
2540
|
+
...appearance?.elements?.headerTitle
|
|
2541
|
+
}, children: "Create your account" }),
|
|
2542
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2543
|
+
padding: "12px 16px",
|
|
2544
|
+
marginBottom: "20px",
|
|
2545
|
+
backgroundColor: "#fee",
|
|
2546
|
+
color: "#c33",
|
|
2547
|
+
border: "1px solid #fcc",
|
|
2548
|
+
borderRadius: "8px",
|
|
2549
|
+
fontSize: "14px"
|
|
2550
|
+
}, children: error }),
|
|
2551
|
+
success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2552
|
+
padding: "12px 16px",
|
|
2553
|
+
marginBottom: "20px",
|
|
2554
|
+
backgroundColor: "#efe",
|
|
2555
|
+
color: "#3c3",
|
|
2556
|
+
border: "1px solid #cfc",
|
|
2557
|
+
borderRadius: "8px",
|
|
2558
|
+
fontSize: "14px"
|
|
2559
|
+
}, children: success }),
|
|
2560
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
2561
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "name", style: {
|
|
2562
|
+
display: "block",
|
|
2563
|
+
marginBottom: "8px",
|
|
2564
|
+
fontWeight: 500,
|
|
2565
|
+
color: "#374151",
|
|
2566
|
+
fontSize: "14px"
|
|
2567
|
+
}, children: "Full name" }),
|
|
2568
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2569
|
+
"input",
|
|
2570
|
+
{
|
|
2571
|
+
id: "name",
|
|
2572
|
+
type: "text",
|
|
2573
|
+
value: name,
|
|
2574
|
+
onChange: (e) => setName(e.target.value),
|
|
2575
|
+
required: true,
|
|
2576
|
+
disabled: isLoading,
|
|
2577
|
+
style: {
|
|
2578
|
+
width: "100%",
|
|
2579
|
+
padding: "12px 16px",
|
|
2580
|
+
border: "1px solid #ddd",
|
|
2581
|
+
borderRadius: "8px",
|
|
2582
|
+
fontSize: "16px",
|
|
2583
|
+
boxSizing: "border-box",
|
|
2584
|
+
...appearance?.elements?.formFieldInput
|
|
2585
|
+
},
|
|
2586
|
+
placeholder: "Enter your full name"
|
|
2587
|
+
}
|
|
2588
|
+
)
|
|
2589
|
+
] }),
|
|
2590
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
2591
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
|
|
2592
|
+
display: "block",
|
|
2593
|
+
marginBottom: "8px",
|
|
2594
|
+
fontWeight: 500,
|
|
2595
|
+
color: "#374151",
|
|
2596
|
+
fontSize: "14px"
|
|
2597
|
+
}, children: "Email" }),
|
|
2598
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2599
|
+
"input",
|
|
2600
|
+
{
|
|
2601
|
+
id: "email",
|
|
2602
|
+
type: "email",
|
|
2603
|
+
value: email,
|
|
2604
|
+
onChange: (e) => setEmail(e.target.value),
|
|
2605
|
+
required: true,
|
|
2606
|
+
disabled: isLoading,
|
|
2607
|
+
style: {
|
|
2608
|
+
width: "100%",
|
|
2609
|
+
padding: "12px 16px",
|
|
2610
|
+
border: "1px solid #ddd",
|
|
2611
|
+
borderRadius: "8px",
|
|
2612
|
+
fontSize: "16px",
|
|
2613
|
+
boxSizing: "border-box",
|
|
2614
|
+
...appearance?.elements?.formFieldInput
|
|
2615
|
+
},
|
|
2616
|
+
placeholder: "Enter your email"
|
|
2617
|
+
}
|
|
2618
|
+
)
|
|
2619
|
+
] }),
|
|
2620
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
|
|
2621
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
|
|
2622
|
+
display: "block",
|
|
2623
|
+
marginBottom: "8px",
|
|
2624
|
+
fontWeight: 500,
|
|
2625
|
+
color: "#374151",
|
|
2626
|
+
fontSize: "14px"
|
|
2627
|
+
}, children: "Password" }),
|
|
2628
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2629
|
+
"input",
|
|
2630
|
+
{
|
|
2631
|
+
id: "password",
|
|
2632
|
+
type: showPassword ? "text" : "password",
|
|
2633
|
+
value: password,
|
|
2634
|
+
onChange: (e) => setPassword(e.target.value),
|
|
2635
|
+
required: true,
|
|
2636
|
+
disabled: isLoading,
|
|
2637
|
+
minLength: 6,
|
|
2638
|
+
style: {
|
|
2639
|
+
width: "100%",
|
|
2640
|
+
padding: "12px 16px",
|
|
2641
|
+
border: "1px solid #ddd",
|
|
2642
|
+
borderRadius: "8px",
|
|
2643
|
+
fontSize: "16px",
|
|
2644
|
+
boxSizing: "border-box",
|
|
2645
|
+
...appearance?.elements?.formFieldInput
|
|
2646
|
+
},
|
|
2647
|
+
placeholder: "Create a password"
|
|
2648
|
+
}
|
|
2649
|
+
),
|
|
2650
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2651
|
+
"button",
|
|
2652
|
+
{
|
|
2653
|
+
type: "button",
|
|
2654
|
+
onClick: () => setShowPassword(!showPassword),
|
|
2655
|
+
style: {
|
|
2656
|
+
position: "absolute",
|
|
2657
|
+
right: "12px",
|
|
2658
|
+
top: "38px",
|
|
2659
|
+
background: "none",
|
|
2660
|
+
border: "none",
|
|
2661
|
+
cursor: "pointer",
|
|
2662
|
+
color: "#666",
|
|
2663
|
+
fontSize: "14px"
|
|
2664
|
+
},
|
|
2665
|
+
children: showPassword ? "Hide" : "Show"
|
|
2666
|
+
}
|
|
2667
|
+
),
|
|
2668
|
+
password && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "8px" }, children: [
|
|
2669
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2670
|
+
height: "4px",
|
|
2671
|
+
backgroundColor: "#eee",
|
|
2672
|
+
borderRadius: "2px",
|
|
2673
|
+
overflow: "hidden"
|
|
2674
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2675
|
+
height: "100%",
|
|
2676
|
+
width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
|
|
2677
|
+
backgroundColor: passwordStrength.color,
|
|
2678
|
+
transition: "all 0.3s ease"
|
|
2679
|
+
} }) }),
|
|
2680
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
|
|
2681
|
+
fontSize: "12px",
|
|
2682
|
+
color: passwordStrength.color,
|
|
2683
|
+
marginTop: "4px",
|
|
2684
|
+
textTransform: "capitalize"
|
|
2685
|
+
}, children: [
|
|
2686
|
+
passwordStrength.strength,
|
|
2687
|
+
" password"
|
|
2688
|
+
] })
|
|
2689
|
+
] })
|
|
2690
|
+
] }),
|
|
2691
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
2692
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "confirmPassword", style: {
|
|
2693
|
+
display: "block",
|
|
2694
|
+
marginBottom: "8px",
|
|
2695
|
+
fontWeight: 500,
|
|
2696
|
+
color: "#374151",
|
|
2697
|
+
fontSize: "14px"
|
|
2698
|
+
}, children: "Confirm password" }),
|
|
2699
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2700
|
+
"input",
|
|
2701
|
+
{
|
|
2702
|
+
id: "confirmPassword",
|
|
2703
|
+
type: showPassword ? "text" : "password",
|
|
2704
|
+
value: confirmPassword,
|
|
2705
|
+
onChange: (e) => setConfirmPassword(e.target.value),
|
|
2706
|
+
required: true,
|
|
2707
|
+
disabled: isLoading,
|
|
2708
|
+
style: {
|
|
2709
|
+
width: "100%",
|
|
2710
|
+
padding: "12px 16px",
|
|
2711
|
+
border: "1px solid #ddd",
|
|
2712
|
+
borderRadius: "8px",
|
|
2713
|
+
fontSize: "16px",
|
|
2714
|
+
boxSizing: "border-box",
|
|
2715
|
+
...appearance?.elements?.formFieldInput
|
|
2716
|
+
},
|
|
2717
|
+
placeholder: "Confirm your password"
|
|
2718
|
+
}
|
|
2719
|
+
)
|
|
2720
|
+
] }),
|
|
2721
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2722
|
+
"button",
|
|
2723
|
+
{
|
|
2724
|
+
type: "submit",
|
|
2725
|
+
disabled: isLoading,
|
|
2726
|
+
style: {
|
|
2727
|
+
width: "100%",
|
|
2728
|
+
padding: "14px",
|
|
2729
|
+
backgroundColor: "#007bff",
|
|
2730
|
+
color: "white",
|
|
2731
|
+
border: "none",
|
|
2732
|
+
borderRadius: "8px",
|
|
2733
|
+
fontSize: "16px",
|
|
2734
|
+
fontWeight: 600,
|
|
2735
|
+
cursor: "pointer",
|
|
2736
|
+
transition: "all 0.2s ease",
|
|
2737
|
+
...appearance?.elements?.formButtonPrimary
|
|
2738
|
+
},
|
|
2739
|
+
children: isLoading ? "Creating account..." : "Sign up"
|
|
2740
|
+
}
|
|
2741
|
+
)
|
|
2742
|
+
] }) });
|
|
2743
|
+
};
|
|
2744
|
+
var SignOut = ({ redirectUrl }) => {
|
|
2745
|
+
const { signOut } = useAuth();
|
|
2746
|
+
react.useEffect(() => {
|
|
2747
|
+
const performSignOut = async () => {
|
|
2748
|
+
await signOut();
|
|
2749
|
+
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
|
|
2750
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
2751
|
+
window.location.href = `${baseUrl}${redirect}`;
|
|
2752
|
+
};
|
|
2753
|
+
performSignOut();
|
|
2754
|
+
}, [signOut, redirectUrl]);
|
|
2755
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Signing out..." }) });
|
|
2756
|
+
};
|
|
2757
|
+
var UserButton = ({ showName = false, appearance }) => {
|
|
2758
|
+
const { user, signOut } = useAuth();
|
|
2759
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
2760
|
+
const dropdownRef = react.useRef(null);
|
|
2761
|
+
react.useEffect(() => {
|
|
2762
|
+
const handleClickOutside = (event) => {
|
|
2763
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
2764
|
+
setIsOpen(false);
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2768
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
2769
|
+
}, []);
|
|
2770
|
+
if (!user)
|
|
2771
|
+
return null;
|
|
2772
|
+
const getInitials = (name) => {
|
|
2773
|
+
return name.split(" ").map((n) => n[0]).join("").toUpperCase().slice(0, 2);
|
|
2774
|
+
};
|
|
2775
|
+
const handleSignOut = async () => {
|
|
2776
|
+
await signOut();
|
|
2777
|
+
const redirect = process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
|
|
2778
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
2779
|
+
window.location.href = `${baseUrl}${redirect}`;
|
|
2780
|
+
};
|
|
2781
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative", ...appearance?.elements?.userButtonBox }, ref: dropdownRef, children: [
|
|
2782
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2783
|
+
"button",
|
|
2784
|
+
{
|
|
2785
|
+
onClick: () => setIsOpen(!isOpen),
|
|
2786
|
+
style: {
|
|
2787
|
+
display: "flex",
|
|
2788
|
+
alignItems: "center",
|
|
2789
|
+
gap: "8px",
|
|
2790
|
+
padding: "6px",
|
|
2791
|
+
backgroundColor: "transparent",
|
|
2792
|
+
border: "none",
|
|
2793
|
+
borderRadius: "8px",
|
|
2794
|
+
cursor: "pointer",
|
|
2795
|
+
transition: "background-color 0.2s",
|
|
2796
|
+
...appearance?.elements?.userButtonTrigger
|
|
2797
|
+
},
|
|
2798
|
+
onMouseEnter: (e) => {
|
|
2799
|
+
e.currentTarget.style.backgroundColor = "#f5f5f5";
|
|
2800
|
+
},
|
|
2801
|
+
onMouseLeave: (e) => {
|
|
2802
|
+
e.currentTarget.style.backgroundColor = "transparent";
|
|
2803
|
+
},
|
|
2804
|
+
children: [
|
|
2805
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2806
|
+
width: "36px",
|
|
2807
|
+
height: "36px",
|
|
2808
|
+
borderRadius: "50%",
|
|
2809
|
+
backgroundColor: "#007bff",
|
|
2810
|
+
color: "white",
|
|
2811
|
+
display: "flex",
|
|
2812
|
+
alignItems: "center",
|
|
2813
|
+
justifyContent: "center",
|
|
2814
|
+
fontSize: "14px",
|
|
2815
|
+
fontWeight: 600
|
|
2816
|
+
}, children: getInitials(user.name) }),
|
|
2817
|
+
showName && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "14px", fontWeight: 500, color: "#333" }, children: user.name })
|
|
2818
|
+
]
|
|
2819
|
+
}
|
|
2820
|
+
),
|
|
2821
|
+
isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
2822
|
+
position: "absolute",
|
|
2823
|
+
top: "100%",
|
|
2824
|
+
right: 0,
|
|
2825
|
+
marginTop: "8px",
|
|
2826
|
+
width: "240px",
|
|
2827
|
+
backgroundColor: "white",
|
|
2828
|
+
borderRadius: "12px",
|
|
2829
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.15)",
|
|
2830
|
+
border: "1px solid #eaeaea",
|
|
2831
|
+
zIndex: 1e3,
|
|
2832
|
+
...appearance?.elements?.userButtonPopoverCard
|
|
2833
|
+
}, children: [
|
|
2834
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2835
|
+
padding: "16px",
|
|
2836
|
+
borderBottom: "1px solid #eee"
|
|
2837
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
2838
|
+
display: "flex",
|
|
2839
|
+
alignItems: "center",
|
|
2840
|
+
gap: "12px"
|
|
2841
|
+
}, children: [
|
|
2842
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2843
|
+
width: "48px",
|
|
2844
|
+
height: "48px",
|
|
2845
|
+
borderRadius: "50%",
|
|
2846
|
+
backgroundColor: "#007bff",
|
|
2847
|
+
color: "white",
|
|
2848
|
+
display: "flex",
|
|
2849
|
+
alignItems: "center",
|
|
2850
|
+
justifyContent: "center",
|
|
2851
|
+
fontSize: "18px",
|
|
2852
|
+
fontWeight: 600
|
|
2853
|
+
}, children: getInitials(user.name) }),
|
|
2854
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
2855
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2856
|
+
fontSize: "14px",
|
|
2857
|
+
fontWeight: 600,
|
|
2858
|
+
color: "#333",
|
|
2859
|
+
overflow: "hidden",
|
|
2860
|
+
textOverflow: "ellipsis",
|
|
2861
|
+
whiteSpace: "nowrap"
|
|
2862
|
+
}, children: user.name }),
|
|
2863
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2864
|
+
fontSize: "12px",
|
|
2865
|
+
color: "#666",
|
|
2866
|
+
overflow: "hidden",
|
|
2867
|
+
textOverflow: "ellipsis",
|
|
2868
|
+
whiteSpace: "nowrap"
|
|
2869
|
+
}, children: user.email })
|
|
2870
|
+
] })
|
|
2871
|
+
] }) }),
|
|
2872
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "8px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2873
|
+
"button",
|
|
2874
|
+
{
|
|
2875
|
+
onClick: handleSignOut,
|
|
2876
|
+
style: {
|
|
2877
|
+
width: "100%",
|
|
2878
|
+
padding: "10px 16px",
|
|
2879
|
+
backgroundColor: "transparent",
|
|
2880
|
+
border: "none",
|
|
2881
|
+
borderRadius: "8px",
|
|
2882
|
+
textAlign: "left",
|
|
2883
|
+
cursor: "pointer",
|
|
2884
|
+
fontSize: "14px",
|
|
2885
|
+
color: "#333",
|
|
2886
|
+
fontWeight: 500,
|
|
2887
|
+
transition: "background-color 0.2s"
|
|
2888
|
+
},
|
|
2889
|
+
onMouseEnter: (e) => {
|
|
2890
|
+
e.currentTarget.style.backgroundColor = "#f5f5f5";
|
|
2891
|
+
},
|
|
2892
|
+
onMouseLeave: (e) => {
|
|
2893
|
+
e.currentTarget.style.backgroundColor = "transparent";
|
|
2894
|
+
},
|
|
2895
|
+
children: "Sign out"
|
|
2896
|
+
}
|
|
2897
|
+
) })
|
|
2898
|
+
] })
|
|
2899
|
+
] });
|
|
2900
|
+
};
|
|
2901
|
+
var ProtectedRoute = ({
|
|
2902
|
+
children,
|
|
2903
|
+
fallback,
|
|
2904
|
+
redirectTo
|
|
2905
|
+
}) => {
|
|
2906
|
+
const { isSignedIn, isLoaded } = useAuth();
|
|
2907
|
+
react.useEffect(() => {
|
|
2908
|
+
if (isLoaded && !isSignedIn) {
|
|
2909
|
+
const loginPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
2910
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
2911
|
+
window.location.href = `${baseUrl}${loginPath}`;
|
|
2912
|
+
}
|
|
2913
|
+
}, [isSignedIn, isLoaded, redirectTo]);
|
|
2914
|
+
if (!isLoaded) {
|
|
2915
|
+
return fallback || /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2916
|
+
display: "flex",
|
|
2917
|
+
justifyContent: "center",
|
|
2918
|
+
alignItems: "center",
|
|
2919
|
+
minHeight: "100vh"
|
|
2920
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }) });
|
|
2921
|
+
}
|
|
2922
|
+
if (!isSignedIn) {
|
|
2923
|
+
return fallback || null;
|
|
2924
|
+
}
|
|
2925
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
2926
|
+
};
|
|
2927
|
+
var PublicRoute = ({
|
|
2928
|
+
children,
|
|
2929
|
+
redirectTo
|
|
2930
|
+
}) => {
|
|
2931
|
+
const { isSignedIn, isLoaded } = useAuth();
|
|
2932
|
+
react.useEffect(() => {
|
|
2933
|
+
if (isLoaded && isSignedIn) {
|
|
2934
|
+
const dashboardPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
2935
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
2936
|
+
window.location.href = `${baseUrl}${dashboardPath}`;
|
|
2937
|
+
}
|
|
2938
|
+
}, [isSignedIn, isLoaded, redirectTo]);
|
|
2939
|
+
if (!isLoaded) {
|
|
2940
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
2941
|
+
display: "flex",
|
|
2942
|
+
justifyContent: "center",
|
|
2943
|
+
alignItems: "center",
|
|
2944
|
+
minHeight: "100vh"
|
|
2945
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }) });
|
|
2946
|
+
}
|
|
2947
|
+
if (isSignedIn) {
|
|
2948
|
+
return null;
|
|
2949
|
+
}
|
|
2950
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
2951
|
+
};
|
|
2952
|
+
var VerifyEmail = ({ token, onSuccess, onError }) => {
|
|
2953
|
+
const { verifyEmailToken } = useAuth();
|
|
2954
|
+
const [status, setStatus] = react.useState("loading");
|
|
2955
|
+
const [message, setMessage] = react.useState("");
|
|
2956
|
+
react.useEffect(() => {
|
|
2957
|
+
const verify = async () => {
|
|
2958
|
+
const verifyToken = token || (typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("token") : null);
|
|
2959
|
+
if (!verifyToken) {
|
|
2960
|
+
setStatus("error");
|
|
2961
|
+
setMessage("No verification token provided");
|
|
2962
|
+
onError?.("No verification token provided");
|
|
2963
|
+
return;
|
|
2964
|
+
}
|
|
2965
|
+
try {
|
|
2966
|
+
const response = await verifyEmailToken(verifyToken);
|
|
2967
|
+
if (response.success) {
|
|
2968
|
+
setStatus("success");
|
|
2969
|
+
setMessage("Email verified successfully! Redirecting...");
|
|
2970
|
+
onSuccess?.();
|
|
2971
|
+
setTimeout(() => {
|
|
2972
|
+
const redirect = process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_VERIFY || process.env.REACT_APP_AUTH_REDIRECT_AFTER_VERIFY || "/dashboard";
|
|
2973
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
2974
|
+
window.location.href = `${baseUrl}${redirect}`;
|
|
2975
|
+
}, 2e3);
|
|
2976
|
+
} else {
|
|
2977
|
+
setStatus("error");
|
|
2978
|
+
setMessage(response.message || "Verification failed");
|
|
2979
|
+
onError?.(response.message || "Verification failed");
|
|
2980
|
+
}
|
|
2981
|
+
} catch (err) {
|
|
2982
|
+
setStatus("error");
|
|
2983
|
+
const errorMsg = err instanceof Error ? err.message : "An error occurred";
|
|
2984
|
+
setMessage(errorMsg);
|
|
2985
|
+
onError?.(errorMsg);
|
|
2986
|
+
}
|
|
2987
|
+
};
|
|
2988
|
+
verify();
|
|
2989
|
+
}, [token, verifyEmailToken, onSuccess, onError]);
|
|
2990
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
2991
|
+
maxWidth: "400px",
|
|
2992
|
+
margin: "40px auto",
|
|
2993
|
+
padding: "30px",
|
|
2994
|
+
borderRadius: "12px",
|
|
2995
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
2996
|
+
backgroundColor: "#ffffff",
|
|
2997
|
+
border: "1px solid #eaeaea",
|
|
2998
|
+
textAlign: "center"
|
|
2999
|
+
}, children: [
|
|
3000
|
+
status === "loading" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3001
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3002
|
+
width: "48px",
|
|
3003
|
+
height: "48px",
|
|
3004
|
+
margin: "0 auto 20px",
|
|
3005
|
+
border: "4px solid #f3f3f3",
|
|
3006
|
+
borderTop: "4px solid #007bff",
|
|
3007
|
+
borderRadius: "50%",
|
|
3008
|
+
animation: "spin 1s linear infinite"
|
|
3009
|
+
} }),
|
|
3010
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
3011
|
+
@keyframes spin {
|
|
3012
|
+
0% { transform: rotate(0deg); }
|
|
3013
|
+
100% { transform: rotate(360deg); }
|
|
3014
|
+
}
|
|
3015
|
+
` }),
|
|
3016
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
3017
|
+
fontSize: "20px",
|
|
3018
|
+
fontWeight: 600,
|
|
3019
|
+
color: "#333",
|
|
3020
|
+
marginBottom: "12px"
|
|
3021
|
+
}, children: "Verifying your email..." }),
|
|
3022
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666" }, children: "Please wait while we verify your email address." })
|
|
3023
|
+
] }),
|
|
3024
|
+
status === "success" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3025
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3026
|
+
width: "64px",
|
|
3027
|
+
height: "64px",
|
|
3028
|
+
margin: "0 auto 20px",
|
|
3029
|
+
backgroundColor: "#4caf50",
|
|
3030
|
+
borderRadius: "50%",
|
|
3031
|
+
display: "flex",
|
|
3032
|
+
alignItems: "center",
|
|
3033
|
+
justifyContent: "center"
|
|
3034
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "3", children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "20 6 9 17 4 12" }) }) }),
|
|
3035
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
3036
|
+
fontSize: "20px",
|
|
3037
|
+
fontWeight: 600,
|
|
3038
|
+
color: "#333",
|
|
3039
|
+
marginBottom: "12px"
|
|
3040
|
+
}, children: "Email Verified!" }),
|
|
3041
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666" }, children: message })
|
|
3042
|
+
] }),
|
|
3043
|
+
status === "error" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3044
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3045
|
+
width: "64px",
|
|
3046
|
+
height: "64px",
|
|
3047
|
+
margin: "0 auto 20px",
|
|
3048
|
+
backgroundColor: "#f44336",
|
|
3049
|
+
borderRadius: "50%",
|
|
3050
|
+
display: "flex",
|
|
3051
|
+
alignItems: "center",
|
|
3052
|
+
justifyContent: "center"
|
|
3053
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "3", children: [
|
|
3054
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
3055
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
3056
|
+
] }) }),
|
|
3057
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
3058
|
+
fontSize: "20px",
|
|
3059
|
+
fontWeight: 600,
|
|
3060
|
+
color: "#333",
|
|
3061
|
+
marginBottom: "12px"
|
|
3062
|
+
}, children: "Verification Failed" }),
|
|
3063
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666", marginBottom: "20px" }, children: message }),
|
|
3064
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3065
|
+
"button",
|
|
3066
|
+
{
|
|
3067
|
+
onClick: () => {
|
|
3068
|
+
const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
3069
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
3070
|
+
window.location.href = `${baseUrl}${loginPath}`;
|
|
3071
|
+
},
|
|
3072
|
+
style: {
|
|
3073
|
+
padding: "10px 20px",
|
|
3074
|
+
backgroundColor: "#007bff",
|
|
3075
|
+
color: "white",
|
|
3076
|
+
border: "none",
|
|
3077
|
+
borderRadius: "8px",
|
|
3078
|
+
fontSize: "14px",
|
|
3079
|
+
fontWeight: 600,
|
|
3080
|
+
cursor: "pointer"
|
|
3081
|
+
},
|
|
3082
|
+
children: "Go to Login"
|
|
3083
|
+
}
|
|
3084
|
+
)
|
|
3085
|
+
] })
|
|
3086
|
+
] });
|
|
3087
|
+
};
|
|
3088
|
+
var ForgotPassword = ({ appearance }) => {
|
|
3089
|
+
const { forgotPassword } = useAuth();
|
|
3090
|
+
const [email, setEmail] = react.useState("");
|
|
3091
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
3092
|
+
const [error, setError] = react.useState(null);
|
|
3093
|
+
const [success, setSuccess] = react.useState(null);
|
|
3094
|
+
const handleSubmit = async (e) => {
|
|
3095
|
+
e.preventDefault();
|
|
3096
|
+
setIsLoading(true);
|
|
3097
|
+
setError(null);
|
|
3098
|
+
setSuccess(null);
|
|
3099
|
+
try {
|
|
3100
|
+
const response = await forgotPassword(email);
|
|
3101
|
+
if (response.success) {
|
|
3102
|
+
setSuccess("Password reset link sent! Please check your email.");
|
|
3103
|
+
setEmail("");
|
|
3104
|
+
} else {
|
|
3105
|
+
setError(response.message || "Failed to send reset link");
|
|
3106
|
+
}
|
|
3107
|
+
} catch (err) {
|
|
3108
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
3109
|
+
} finally {
|
|
3110
|
+
setIsLoading(false);
|
|
3111
|
+
}
|
|
3112
|
+
};
|
|
3113
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3114
|
+
maxWidth: "400px",
|
|
3115
|
+
margin: "0 auto",
|
|
3116
|
+
padding: "30px",
|
|
3117
|
+
borderRadius: "12px",
|
|
3118
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
3119
|
+
backgroundColor: "#ffffff",
|
|
3120
|
+
border: "1px solid #eaeaea",
|
|
3121
|
+
...appearance?.elements?.card
|
|
3122
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
|
|
3123
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
3124
|
+
textAlign: "center",
|
|
3125
|
+
marginBottom: "12px",
|
|
3126
|
+
color: "#1f2937",
|
|
3127
|
+
fontSize: "24px",
|
|
3128
|
+
fontWeight: 600,
|
|
3129
|
+
...appearance?.elements?.headerTitle
|
|
3130
|
+
}, children: "Forgot password?" }),
|
|
3131
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: {
|
|
3132
|
+
textAlign: "center",
|
|
3133
|
+
marginBottom: "24px",
|
|
3134
|
+
color: "#666",
|
|
3135
|
+
fontSize: "14px"
|
|
3136
|
+
}, children: "Enter your email address and we'll send you a link to reset your password." }),
|
|
3137
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3138
|
+
padding: "12px 16px",
|
|
3139
|
+
marginBottom: "20px",
|
|
3140
|
+
backgroundColor: "#fee",
|
|
3141
|
+
color: "#c33",
|
|
3142
|
+
border: "1px solid #fcc",
|
|
3143
|
+
borderRadius: "8px",
|
|
3144
|
+
fontSize: "14px"
|
|
3145
|
+
}, children: error }),
|
|
3146
|
+
success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3147
|
+
padding: "12px 16px",
|
|
3148
|
+
marginBottom: "20px",
|
|
3149
|
+
backgroundColor: "#efe",
|
|
3150
|
+
color: "#3c3",
|
|
3151
|
+
border: "1px solid #cfc",
|
|
3152
|
+
borderRadius: "8px",
|
|
3153
|
+
fontSize: "14px"
|
|
3154
|
+
}, children: success }),
|
|
3155
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
3156
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
|
|
3157
|
+
display: "block",
|
|
3158
|
+
marginBottom: "8px",
|
|
3159
|
+
fontWeight: 500,
|
|
3160
|
+
color: "#374151",
|
|
3161
|
+
fontSize: "14px"
|
|
3162
|
+
}, children: "Email" }),
|
|
3163
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3164
|
+
"input",
|
|
3165
|
+
{
|
|
3166
|
+
id: "email",
|
|
3167
|
+
type: "email",
|
|
3168
|
+
value: email,
|
|
3169
|
+
onChange: (e) => setEmail(e.target.value),
|
|
3170
|
+
required: true,
|
|
3171
|
+
disabled: isLoading,
|
|
3172
|
+
style: {
|
|
3173
|
+
width: "100%",
|
|
3174
|
+
padding: "12px 16px",
|
|
3175
|
+
border: "1px solid #ddd",
|
|
3176
|
+
borderRadius: "8px",
|
|
3177
|
+
fontSize: "16px",
|
|
3178
|
+
boxSizing: "border-box",
|
|
3179
|
+
...appearance?.elements?.formFieldInput
|
|
3180
|
+
},
|
|
3181
|
+
placeholder: "Enter your email"
|
|
3182
|
+
}
|
|
3183
|
+
)
|
|
3184
|
+
] }),
|
|
3185
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3186
|
+
"button",
|
|
3187
|
+
{
|
|
3188
|
+
type: "submit",
|
|
3189
|
+
disabled: isLoading,
|
|
3190
|
+
style: {
|
|
3191
|
+
width: "100%",
|
|
3192
|
+
padding: "14px",
|
|
3193
|
+
backgroundColor: "#007bff",
|
|
3194
|
+
color: "white",
|
|
3195
|
+
border: "none",
|
|
3196
|
+
borderRadius: "8px",
|
|
3197
|
+
fontSize: "16px",
|
|
3198
|
+
fontWeight: 600,
|
|
3199
|
+
cursor: "pointer",
|
|
3200
|
+
transition: "all 0.2s ease",
|
|
3201
|
+
marginBottom: "16px",
|
|
3202
|
+
...appearance?.elements?.formButtonPrimary
|
|
3203
|
+
},
|
|
3204
|
+
children: isLoading ? "Sending..." : "Send reset link"
|
|
3205
|
+
}
|
|
3206
|
+
),
|
|
3207
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3208
|
+
"button",
|
|
3209
|
+
{
|
|
3210
|
+
type: "button",
|
|
3211
|
+
onClick: () => {
|
|
3212
|
+
const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
3213
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
3214
|
+
window.location.href = `${baseUrl}${loginPath}`;
|
|
3215
|
+
},
|
|
3216
|
+
disabled: isLoading,
|
|
3217
|
+
style: {
|
|
3218
|
+
background: "none",
|
|
3219
|
+
border: "none",
|
|
3220
|
+
color: "#007bff",
|
|
3221
|
+
cursor: "pointer",
|
|
3222
|
+
fontSize: "14px",
|
|
3223
|
+
fontWeight: 600
|
|
3224
|
+
},
|
|
3225
|
+
children: "Back to sign in"
|
|
3226
|
+
}
|
|
3227
|
+
) })
|
|
3228
|
+
] }) });
|
|
3229
|
+
};
|
|
3230
|
+
var ResetPassword = ({ token, appearance }) => {
|
|
3231
|
+
const { resetPassword } = useAuth();
|
|
3232
|
+
const [resetToken, setResetToken] = react.useState(token || "");
|
|
3233
|
+
const [password, setPassword] = react.useState("");
|
|
3234
|
+
const [confirmPassword, setConfirmPassword] = react.useState("");
|
|
3235
|
+
const [showPassword, setShowPassword] = react.useState(false);
|
|
3236
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
3237
|
+
const [error, setError] = react.useState(null);
|
|
3238
|
+
const [success, setSuccess] = react.useState(false);
|
|
3239
|
+
react.useEffect(() => {
|
|
3240
|
+
if (!resetToken && typeof window !== "undefined") {
|
|
3241
|
+
const urlToken = new URLSearchParams(window.location.search).get("token");
|
|
3242
|
+
if (urlToken) {
|
|
3243
|
+
setResetToken(urlToken);
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
}, [resetToken]);
|
|
3247
|
+
const getPasswordStrength = (pwd) => {
|
|
3248
|
+
if (!pwd)
|
|
3249
|
+
return { strength: "weak", color: "#ddd" };
|
|
3250
|
+
let score = 0;
|
|
3251
|
+
if (pwd.length >= 6)
|
|
3252
|
+
score++;
|
|
3253
|
+
if (pwd.length >= 8)
|
|
3254
|
+
score++;
|
|
3255
|
+
if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
|
|
3256
|
+
score++;
|
|
3257
|
+
if (/\d/.test(pwd))
|
|
3258
|
+
score++;
|
|
3259
|
+
if (/[^a-zA-Z\d]/.test(pwd))
|
|
3260
|
+
score++;
|
|
3261
|
+
if (score <= 2)
|
|
3262
|
+
return { strength: "weak", color: "#f44" };
|
|
3263
|
+
if (score <= 3)
|
|
3264
|
+
return { strength: "medium", color: "#fa4" };
|
|
3265
|
+
return { strength: "strong", color: "#4f4" };
|
|
3266
|
+
};
|
|
3267
|
+
const passwordStrength = getPasswordStrength(password);
|
|
3268
|
+
const handleSubmit = async (e) => {
|
|
3269
|
+
e.preventDefault();
|
|
3270
|
+
setIsLoading(true);
|
|
3271
|
+
setError(null);
|
|
3272
|
+
if (password !== confirmPassword) {
|
|
3273
|
+
setError("Passwords do not match");
|
|
3274
|
+
setIsLoading(false);
|
|
3275
|
+
return;
|
|
3276
|
+
}
|
|
3277
|
+
if (password.length < 6) {
|
|
3278
|
+
setError("Password must be at least 6 characters");
|
|
3279
|
+
setIsLoading(false);
|
|
3280
|
+
return;
|
|
3281
|
+
}
|
|
3282
|
+
if (!resetToken) {
|
|
3283
|
+
setError("Invalid reset token");
|
|
3284
|
+
setIsLoading(false);
|
|
3285
|
+
return;
|
|
3286
|
+
}
|
|
3287
|
+
try {
|
|
3288
|
+
const response = await resetPassword(resetToken, password);
|
|
3289
|
+
if (response.success) {
|
|
3290
|
+
setSuccess(true);
|
|
3291
|
+
setTimeout(() => {
|
|
3292
|
+
const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
3293
|
+
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
3294
|
+
window.location.href = `${baseUrl}${loginPath}`;
|
|
3295
|
+
}, 2e3);
|
|
3296
|
+
} else {
|
|
3297
|
+
setError(response.message || "Failed to reset password");
|
|
3298
|
+
}
|
|
3299
|
+
} catch (err) {
|
|
3300
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
3301
|
+
} finally {
|
|
3302
|
+
setIsLoading(false);
|
|
3303
|
+
}
|
|
3304
|
+
};
|
|
3305
|
+
if (success) {
|
|
3306
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
3307
|
+
maxWidth: "400px",
|
|
3308
|
+
margin: "40px auto",
|
|
3309
|
+
padding: "30px",
|
|
3310
|
+
borderRadius: "12px",
|
|
3311
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
3312
|
+
backgroundColor: "#ffffff",
|
|
3313
|
+
border: "1px solid #eaeaea",
|
|
3314
|
+
textAlign: "center"
|
|
3315
|
+
}, children: [
|
|
3316
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3317
|
+
width: "64px",
|
|
3318
|
+
height: "64px",
|
|
3319
|
+
margin: "0 auto 20px",
|
|
3320
|
+
backgroundColor: "#4caf50",
|
|
3321
|
+
borderRadius: "50%",
|
|
3322
|
+
display: "flex",
|
|
3323
|
+
alignItems: "center",
|
|
3324
|
+
justifyContent: "center"
|
|
3325
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "3", children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "20 6 9 17 4 12" }) }) }),
|
|
3326
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
3327
|
+
fontSize: "20px",
|
|
3328
|
+
fontWeight: 600,
|
|
3329
|
+
color: "#333",
|
|
3330
|
+
marginBottom: "12px"
|
|
3331
|
+
}, children: "Password Reset Successful!" }),
|
|
3332
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666" }, children: "Your password has been reset. Redirecting to login..." })
|
|
3333
|
+
] });
|
|
3334
|
+
}
|
|
3335
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3336
|
+
maxWidth: "400px",
|
|
3337
|
+
margin: "0 auto",
|
|
3338
|
+
padding: "30px",
|
|
3339
|
+
borderRadius: "12px",
|
|
3340
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
3341
|
+
backgroundColor: "#ffffff",
|
|
3342
|
+
border: "1px solid #eaeaea",
|
|
3343
|
+
...appearance?.elements?.card
|
|
3344
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
|
|
3345
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
3346
|
+
textAlign: "center",
|
|
3347
|
+
marginBottom: "12px",
|
|
3348
|
+
color: "#1f2937",
|
|
3349
|
+
fontSize: "24px",
|
|
3350
|
+
fontWeight: 600,
|
|
3351
|
+
...appearance?.elements?.headerTitle
|
|
3352
|
+
}, children: "Reset your password" }),
|
|
3353
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: {
|
|
3354
|
+
textAlign: "center",
|
|
3355
|
+
marginBottom: "24px",
|
|
3356
|
+
color: "#666",
|
|
3357
|
+
fontSize: "14px"
|
|
3358
|
+
}, children: "Enter your new password below." }),
|
|
3359
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3360
|
+
padding: "12px 16px",
|
|
3361
|
+
marginBottom: "20px",
|
|
3362
|
+
backgroundColor: "#fee",
|
|
3363
|
+
color: "#c33",
|
|
3364
|
+
border: "1px solid #fcc",
|
|
3365
|
+
borderRadius: "8px",
|
|
3366
|
+
fontSize: "14px"
|
|
3367
|
+
}, children: error }),
|
|
3368
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
|
|
3369
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
|
|
3370
|
+
display: "block",
|
|
3371
|
+
marginBottom: "8px",
|
|
3372
|
+
fontWeight: 500,
|
|
3373
|
+
color: "#374151",
|
|
3374
|
+
fontSize: "14px"
|
|
3375
|
+
}, children: "New password" }),
|
|
3376
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3377
|
+
"input",
|
|
3378
|
+
{
|
|
3379
|
+
id: "password",
|
|
3380
|
+
type: showPassword ? "text" : "password",
|
|
3381
|
+
value: password,
|
|
3382
|
+
onChange: (e) => setPassword(e.target.value),
|
|
3383
|
+
required: true,
|
|
3384
|
+
disabled: isLoading,
|
|
3385
|
+
minLength: 6,
|
|
3386
|
+
style: {
|
|
3387
|
+
width: "100%",
|
|
3388
|
+
padding: "12px 16px",
|
|
3389
|
+
border: "1px solid #ddd",
|
|
3390
|
+
borderRadius: "8px",
|
|
3391
|
+
fontSize: "16px",
|
|
3392
|
+
boxSizing: "border-box",
|
|
3393
|
+
...appearance?.elements?.formFieldInput
|
|
3394
|
+
},
|
|
3395
|
+
placeholder: "Enter new password"
|
|
3396
|
+
}
|
|
3397
|
+
),
|
|
3398
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3399
|
+
"button",
|
|
3400
|
+
{
|
|
3401
|
+
type: "button",
|
|
3402
|
+
onClick: () => setShowPassword(!showPassword),
|
|
3403
|
+
style: {
|
|
3404
|
+
position: "absolute",
|
|
3405
|
+
right: "12px",
|
|
3406
|
+
top: "38px",
|
|
3407
|
+
background: "none",
|
|
3408
|
+
border: "none",
|
|
3409
|
+
cursor: "pointer",
|
|
3410
|
+
color: "#666",
|
|
3411
|
+
fontSize: "14px"
|
|
3412
|
+
},
|
|
3413
|
+
children: showPassword ? "Hide" : "Show"
|
|
3414
|
+
}
|
|
3415
|
+
),
|
|
3416
|
+
password && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "8px" }, children: [
|
|
3417
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3418
|
+
height: "4px",
|
|
3419
|
+
backgroundColor: "#eee",
|
|
3420
|
+
borderRadius: "2px",
|
|
3421
|
+
overflow: "hidden"
|
|
3422
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3423
|
+
height: "100%",
|
|
3424
|
+
width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
|
|
3425
|
+
backgroundColor: passwordStrength.color,
|
|
3426
|
+
transition: "all 0.3s ease"
|
|
3427
|
+
} }) }),
|
|
3428
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
|
|
3429
|
+
fontSize: "12px",
|
|
3430
|
+
color: passwordStrength.color,
|
|
3431
|
+
marginTop: "4px",
|
|
3432
|
+
textTransform: "capitalize"
|
|
3433
|
+
}, children: [
|
|
3434
|
+
passwordStrength.strength,
|
|
3435
|
+
" password"
|
|
3436
|
+
] })
|
|
3437
|
+
] })
|
|
3438
|
+
] }),
|
|
3439
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
3440
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "confirmPassword", style: {
|
|
3441
|
+
display: "block",
|
|
3442
|
+
marginBottom: "8px",
|
|
3443
|
+
fontWeight: 500,
|
|
3444
|
+
color: "#374151",
|
|
3445
|
+
fontSize: "14px"
|
|
3446
|
+
}, children: "Confirm password" }),
|
|
3447
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3448
|
+
"input",
|
|
3449
|
+
{
|
|
3450
|
+
id: "confirmPassword",
|
|
3451
|
+
type: showPassword ? "text" : "password",
|
|
3452
|
+
value: confirmPassword,
|
|
3453
|
+
onChange: (e) => setConfirmPassword(e.target.value),
|
|
3454
|
+
required: true,
|
|
3455
|
+
disabled: isLoading,
|
|
3456
|
+
style: {
|
|
3457
|
+
width: "100%",
|
|
3458
|
+
padding: "12px 16px",
|
|
3459
|
+
border: "1px solid #ddd",
|
|
3460
|
+
borderRadius: "8px",
|
|
3461
|
+
fontSize: "16px",
|
|
3462
|
+
boxSizing: "border-box",
|
|
3463
|
+
...appearance?.elements?.formFieldInput
|
|
3464
|
+
},
|
|
3465
|
+
placeholder: "Confirm new password"
|
|
3466
|
+
}
|
|
3467
|
+
)
|
|
3468
|
+
] }),
|
|
3469
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3470
|
+
"button",
|
|
3471
|
+
{
|
|
3472
|
+
type: "submit",
|
|
3473
|
+
disabled: isLoading,
|
|
3474
|
+
style: {
|
|
3475
|
+
width: "100%",
|
|
3476
|
+
padding: "14px",
|
|
3477
|
+
backgroundColor: "#007bff",
|
|
3478
|
+
color: "white",
|
|
3479
|
+
border: "none",
|
|
3480
|
+
borderRadius: "8px",
|
|
3481
|
+
fontSize: "16px",
|
|
3482
|
+
fontWeight: 600,
|
|
3483
|
+
cursor: "pointer",
|
|
3484
|
+
transition: "all 0.2s ease",
|
|
3485
|
+
...appearance?.elements?.formButtonPrimary
|
|
3486
|
+
},
|
|
3487
|
+
children: isLoading ? "Resetting..." : "Reset password"
|
|
3488
|
+
}
|
|
3489
|
+
)
|
|
3490
|
+
] }) });
|
|
3491
|
+
};
|
|
3492
|
+
var ChangePassword = ({ onSuccess, appearance }) => {
|
|
3493
|
+
const { changePassword } = useAuth();
|
|
3494
|
+
const [oldPassword, setOldPassword] = react.useState("");
|
|
3495
|
+
const [newPassword, setNewPassword] = react.useState("");
|
|
3496
|
+
const [confirmPassword, setConfirmPassword] = react.useState("");
|
|
3497
|
+
const [showPasswords, setShowPasswords] = react.useState(false);
|
|
3498
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
3499
|
+
const [error, setError] = react.useState(null);
|
|
3500
|
+
const [success, setSuccess] = react.useState(false);
|
|
3501
|
+
const getPasswordStrength = (pwd) => {
|
|
3502
|
+
if (!pwd)
|
|
3503
|
+
return { strength: "weak", color: "#ddd" };
|
|
3504
|
+
let score = 0;
|
|
3505
|
+
if (pwd.length >= 6)
|
|
3506
|
+
score++;
|
|
3507
|
+
if (pwd.length >= 8)
|
|
3508
|
+
score++;
|
|
3509
|
+
if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
|
|
3510
|
+
score++;
|
|
3511
|
+
if (/\d/.test(pwd))
|
|
3512
|
+
score++;
|
|
3513
|
+
if (/[^a-zA-Z\d]/.test(pwd))
|
|
3514
|
+
score++;
|
|
3515
|
+
if (score <= 2)
|
|
3516
|
+
return { strength: "weak", color: "#f44" };
|
|
3517
|
+
if (score <= 3)
|
|
3518
|
+
return { strength: "medium", color: "#fa4" };
|
|
3519
|
+
return { strength: "strong", color: "#4f4" };
|
|
3520
|
+
};
|
|
3521
|
+
const passwordStrength = getPasswordStrength(newPassword);
|
|
3522
|
+
const handleSubmit = async (e) => {
|
|
3523
|
+
e.preventDefault();
|
|
3524
|
+
setIsLoading(true);
|
|
3525
|
+
setError(null);
|
|
3526
|
+
setSuccess(false);
|
|
3527
|
+
if (newPassword !== confirmPassword) {
|
|
3528
|
+
setError("New passwords do not match");
|
|
3529
|
+
setIsLoading(false);
|
|
3530
|
+
return;
|
|
3531
|
+
}
|
|
3532
|
+
if (newPassword.length < 6) {
|
|
3533
|
+
setError("New password must be at least 6 characters");
|
|
3534
|
+
setIsLoading(false);
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
try {
|
|
3538
|
+
const response = await changePassword(oldPassword, newPassword);
|
|
3539
|
+
if (response.success) {
|
|
3540
|
+
setSuccess(true);
|
|
3541
|
+
setOldPassword("");
|
|
3542
|
+
setNewPassword("");
|
|
3543
|
+
setConfirmPassword("");
|
|
3544
|
+
onSuccess?.();
|
|
3545
|
+
} else {
|
|
3546
|
+
setError(response.message || "Failed to change password");
|
|
3547
|
+
}
|
|
3548
|
+
} catch (err) {
|
|
3549
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
3550
|
+
} finally {
|
|
3551
|
+
setIsLoading(false);
|
|
3552
|
+
}
|
|
3553
|
+
};
|
|
3554
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3555
|
+
maxWidth: "400px",
|
|
3556
|
+
margin: "0 auto",
|
|
3557
|
+
padding: "30px",
|
|
3558
|
+
borderRadius: "12px",
|
|
3559
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
|
|
3560
|
+
backgroundColor: "#ffffff",
|
|
3561
|
+
border: "1px solid #eaeaea",
|
|
3562
|
+
...appearance?.elements?.card
|
|
3563
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
|
|
3564
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
|
|
3565
|
+
textAlign: "center",
|
|
3566
|
+
marginBottom: "24px",
|
|
3567
|
+
color: "#1f2937",
|
|
3568
|
+
fontSize: "24px",
|
|
3569
|
+
fontWeight: 600,
|
|
3570
|
+
...appearance?.elements?.headerTitle
|
|
3571
|
+
}, children: "Change Password" }),
|
|
3572
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3573
|
+
padding: "12px 16px",
|
|
3574
|
+
marginBottom: "20px",
|
|
3575
|
+
backgroundColor: "#fee",
|
|
3576
|
+
color: "#c33",
|
|
3577
|
+
border: "1px solid #fcc",
|
|
3578
|
+
borderRadius: "8px",
|
|
3579
|
+
fontSize: "14px"
|
|
3580
|
+
}, children: error }),
|
|
3581
|
+
success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3582
|
+
padding: "12px 16px",
|
|
3583
|
+
marginBottom: "20px",
|
|
3584
|
+
backgroundColor: "#efe",
|
|
3585
|
+
color: "#3c3",
|
|
3586
|
+
border: "1px solid #cfc",
|
|
3587
|
+
borderRadius: "8px",
|
|
3588
|
+
fontSize: "14px"
|
|
3589
|
+
}, children: "Password changed successfully!" }),
|
|
3590
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
3591
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "oldPassword", style: {
|
|
3592
|
+
display: "block",
|
|
3593
|
+
marginBottom: "8px",
|
|
3594
|
+
fontWeight: 500,
|
|
3595
|
+
color: "#374151",
|
|
3596
|
+
fontSize: "14px"
|
|
3597
|
+
}, children: "Current password" }),
|
|
3598
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3599
|
+
"input",
|
|
3600
|
+
{
|
|
3601
|
+
id: "oldPassword",
|
|
3602
|
+
type: showPasswords ? "text" : "password",
|
|
3603
|
+
value: oldPassword,
|
|
3604
|
+
onChange: (e) => setOldPassword(e.target.value),
|
|
3605
|
+
required: true,
|
|
3606
|
+
disabled: isLoading,
|
|
3607
|
+
style: {
|
|
3608
|
+
width: "100%",
|
|
3609
|
+
padding: "12px 16px",
|
|
3610
|
+
border: "1px solid #ddd",
|
|
3611
|
+
borderRadius: "8px",
|
|
3612
|
+
fontSize: "16px",
|
|
3613
|
+
boxSizing: "border-box",
|
|
3614
|
+
...appearance?.elements?.formFieldInput
|
|
3615
|
+
},
|
|
3616
|
+
placeholder: "Enter current password"
|
|
3617
|
+
}
|
|
3618
|
+
)
|
|
3619
|
+
] }),
|
|
3620
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
3621
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "newPassword", style: {
|
|
3622
|
+
display: "block",
|
|
3623
|
+
marginBottom: "8px",
|
|
3624
|
+
fontWeight: 500,
|
|
3625
|
+
color: "#374151",
|
|
3626
|
+
fontSize: "14px"
|
|
3627
|
+
}, children: "New password" }),
|
|
3628
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3629
|
+
"input",
|
|
3630
|
+
{
|
|
3631
|
+
id: "newPassword",
|
|
3632
|
+
type: showPasswords ? "text" : "password",
|
|
3633
|
+
value: newPassword,
|
|
3634
|
+
onChange: (e) => setNewPassword(e.target.value),
|
|
3635
|
+
required: true,
|
|
3636
|
+
disabled: isLoading,
|
|
3637
|
+
minLength: 6,
|
|
3638
|
+
style: {
|
|
3639
|
+
width: "100%",
|
|
3640
|
+
padding: "12px 16px",
|
|
3641
|
+
border: "1px solid #ddd",
|
|
3642
|
+
borderRadius: "8px",
|
|
3643
|
+
fontSize: "16px",
|
|
3644
|
+
boxSizing: "border-box",
|
|
3645
|
+
...appearance?.elements?.formFieldInput
|
|
3646
|
+
},
|
|
3647
|
+
placeholder: "Enter new password"
|
|
3648
|
+
}
|
|
3649
|
+
),
|
|
3650
|
+
newPassword && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "8px" }, children: [
|
|
3651
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3652
|
+
height: "4px",
|
|
3653
|
+
backgroundColor: "#eee",
|
|
3654
|
+
borderRadius: "2px",
|
|
3655
|
+
overflow: "hidden"
|
|
3656
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3657
|
+
height: "100%",
|
|
3658
|
+
width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
|
|
3659
|
+
backgroundColor: passwordStrength.color,
|
|
3660
|
+
transition: "all 0.3s ease"
|
|
3661
|
+
} }) }),
|
|
3662
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
|
|
3663
|
+
fontSize: "12px",
|
|
3664
|
+
color: passwordStrength.color,
|
|
3665
|
+
marginTop: "4px",
|
|
3666
|
+
textTransform: "capitalize"
|
|
3667
|
+
}, children: [
|
|
3668
|
+
passwordStrength.strength,
|
|
3669
|
+
" password"
|
|
3670
|
+
] })
|
|
3671
|
+
] })
|
|
3672
|
+
] }),
|
|
3673
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
|
|
3674
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "confirmPassword", style: {
|
|
3675
|
+
display: "block",
|
|
3676
|
+
marginBottom: "8px",
|
|
3677
|
+
fontWeight: 500,
|
|
3678
|
+
color: "#374151",
|
|
3679
|
+
fontSize: "14px"
|
|
3680
|
+
}, children: "Confirm new password" }),
|
|
3681
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3682
|
+
"input",
|
|
3683
|
+
{
|
|
3684
|
+
id: "confirmPassword",
|
|
3685
|
+
type: showPasswords ? "text" : "password",
|
|
3686
|
+
value: confirmPassword,
|
|
3687
|
+
onChange: (e) => setConfirmPassword(e.target.value),
|
|
3688
|
+
required: true,
|
|
3689
|
+
disabled: isLoading,
|
|
3690
|
+
style: {
|
|
3691
|
+
width: "100%",
|
|
3692
|
+
padding: "12px 16px",
|
|
3693
|
+
border: "1px solid #ddd",
|
|
3694
|
+
borderRadius: "8px",
|
|
3695
|
+
fontSize: "16px",
|
|
3696
|
+
boxSizing: "border-box",
|
|
3697
|
+
...appearance?.elements?.formFieldInput
|
|
3698
|
+
},
|
|
3699
|
+
placeholder: "Confirm new password"
|
|
3700
|
+
}
|
|
3701
|
+
)
|
|
3702
|
+
] }),
|
|
3703
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: "20px" }, children: /* @__PURE__ */ jsxRuntime.jsxs("label", { style: { display: "flex", alignItems: "center", cursor: "pointer" }, children: [
|
|
3704
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3705
|
+
"input",
|
|
3706
|
+
{
|
|
3707
|
+
type: "checkbox",
|
|
3708
|
+
checked: showPasswords,
|
|
3709
|
+
onChange: (e) => setShowPasswords(e.target.checked),
|
|
3710
|
+
style: { marginRight: "8px" }
|
|
3711
|
+
}
|
|
3712
|
+
),
|
|
3713
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "14px", color: "#666" }, children: "Show passwords" })
|
|
3714
|
+
] }) }),
|
|
3715
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3716
|
+
"button",
|
|
3717
|
+
{
|
|
3718
|
+
type: "submit",
|
|
3719
|
+
disabled: isLoading,
|
|
3720
|
+
style: {
|
|
3721
|
+
width: "100%",
|
|
3722
|
+
padding: "14px",
|
|
3723
|
+
backgroundColor: "#007bff",
|
|
3724
|
+
color: "white",
|
|
3725
|
+
border: "none",
|
|
3726
|
+
borderRadius: "8px",
|
|
3727
|
+
fontSize: "16px",
|
|
3728
|
+
fontWeight: 600,
|
|
3729
|
+
cursor: "pointer",
|
|
3730
|
+
transition: "all 0.2s ease",
|
|
3731
|
+
...appearance?.elements?.formButtonPrimary
|
|
3732
|
+
},
|
|
3733
|
+
children: isLoading ? "Changing password..." : "Change password"
|
|
3734
|
+
}
|
|
3735
|
+
)
|
|
3736
|
+
] }) });
|
|
3737
|
+
};
|
|
3738
|
+
var UserProfile = ({
|
|
3739
|
+
showAvatar = true,
|
|
3740
|
+
showEmailChange = true,
|
|
3741
|
+
showPasswordChange = true
|
|
3742
|
+
}) => {
|
|
3743
|
+
const { user, updateProfile, updateAvatar, requestEmailChange } = useAuth();
|
|
3744
|
+
const [name, setName] = react.useState(user?.name || "");
|
|
3745
|
+
const [avatar, setAvatar] = react.useState("");
|
|
3746
|
+
const [newEmail, setNewEmail] = react.useState("");
|
|
3747
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
3748
|
+
const [error, setError] = react.useState(null);
|
|
3749
|
+
const [success, setSuccess] = react.useState(null);
|
|
3750
|
+
const handleUpdateName = async (e) => {
|
|
3751
|
+
e.preventDefault();
|
|
3752
|
+
setIsLoading(true);
|
|
3753
|
+
setError(null);
|
|
3754
|
+
setSuccess(null);
|
|
3755
|
+
try {
|
|
3756
|
+
const response = await updateProfile({ name });
|
|
3757
|
+
if (response.success) {
|
|
3758
|
+
setSuccess("Name updated successfully!");
|
|
3759
|
+
} else {
|
|
3760
|
+
setError(response.message || "Failed to update name");
|
|
3761
|
+
}
|
|
3762
|
+
} catch (err) {
|
|
3763
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
3764
|
+
} finally {
|
|
3765
|
+
setIsLoading(false);
|
|
3766
|
+
}
|
|
3767
|
+
};
|
|
3768
|
+
const handleUpdateAvatar = async (e) => {
|
|
3769
|
+
e.preventDefault();
|
|
3770
|
+
setIsLoading(true);
|
|
3771
|
+
setError(null);
|
|
3772
|
+
setSuccess(null);
|
|
3773
|
+
try {
|
|
3774
|
+
const response = await updateAvatar(avatar);
|
|
3775
|
+
if (response.success) {
|
|
3776
|
+
setSuccess("Avatar updated successfully!");
|
|
3777
|
+
setAvatar("");
|
|
3778
|
+
} else {
|
|
3779
|
+
setError(response.message || "Failed to update avatar");
|
|
3780
|
+
}
|
|
3781
|
+
} catch (err) {
|
|
3782
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
3783
|
+
} finally {
|
|
3784
|
+
setIsLoading(false);
|
|
3785
|
+
}
|
|
3786
|
+
};
|
|
3787
|
+
const handleRequestEmailChange = async (e) => {
|
|
3788
|
+
e.preventDefault();
|
|
3789
|
+
setIsLoading(true);
|
|
3790
|
+
setError(null);
|
|
3791
|
+
setSuccess(null);
|
|
3792
|
+
try {
|
|
3793
|
+
const response = await requestEmailChange(newEmail);
|
|
3794
|
+
if (response.success) {
|
|
3795
|
+
setSuccess("Verification email sent! Please check your inbox.");
|
|
3796
|
+
setNewEmail("");
|
|
3797
|
+
} else {
|
|
3798
|
+
setError(response.message || "Failed to request email change");
|
|
3799
|
+
}
|
|
3800
|
+
} catch (err) {
|
|
3801
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
3802
|
+
} finally {
|
|
3803
|
+
setIsLoading(false);
|
|
3804
|
+
}
|
|
3805
|
+
};
|
|
3806
|
+
if (!user)
|
|
3807
|
+
return null;
|
|
3808
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { maxWidth: "600px", margin: "0 auto", padding: "20px" }, children: [
|
|
3809
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: { marginBottom: "24px", fontSize: "24px", fontWeight: 600 }, children: "Profile Settings" }),
|
|
3810
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3811
|
+
padding: "12px 16px",
|
|
3812
|
+
marginBottom: "20px",
|
|
3813
|
+
backgroundColor: "#fee",
|
|
3814
|
+
color: "#c33",
|
|
3815
|
+
border: "1px solid #fcc",
|
|
3816
|
+
borderRadius: "8px",
|
|
3817
|
+
fontSize: "14px"
|
|
3818
|
+
}, children: error }),
|
|
3819
|
+
success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
3820
|
+
padding: "12px 16px",
|
|
3821
|
+
marginBottom: "20px",
|
|
3822
|
+
backgroundColor: "#efe",
|
|
3823
|
+
color: "#3c3",
|
|
3824
|
+
border: "1px solid #cfc",
|
|
3825
|
+
borderRadius: "8px",
|
|
3826
|
+
fontSize: "14px"
|
|
3827
|
+
}, children: success }),
|
|
3828
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
3829
|
+
padding: "20px",
|
|
3830
|
+
backgroundColor: "#fff",
|
|
3831
|
+
borderRadius: "8px",
|
|
3832
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
|
|
3833
|
+
marginBottom: "20px"
|
|
3834
|
+
}, children: [
|
|
3835
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Update Name" }),
|
|
3836
|
+
/* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleUpdateName, children: [
|
|
3837
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3838
|
+
"input",
|
|
3839
|
+
{
|
|
3840
|
+
type: "text",
|
|
3841
|
+
value: name,
|
|
3842
|
+
onChange: (e) => setName(e.target.value),
|
|
3843
|
+
required: true,
|
|
3844
|
+
disabled: isLoading,
|
|
3845
|
+
style: {
|
|
3846
|
+
width: "100%",
|
|
3847
|
+
padding: "12px 16px",
|
|
3848
|
+
border: "1px solid #ddd",
|
|
3849
|
+
borderRadius: "8px",
|
|
3850
|
+
fontSize: "16px",
|
|
3851
|
+
boxSizing: "border-box",
|
|
3852
|
+
marginBottom: "12px"
|
|
3853
|
+
},
|
|
3854
|
+
placeholder: "Your name"
|
|
3855
|
+
}
|
|
3856
|
+
),
|
|
3857
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3858
|
+
"button",
|
|
3859
|
+
{
|
|
3860
|
+
type: "submit",
|
|
3861
|
+
disabled: isLoading,
|
|
3862
|
+
style: {
|
|
3863
|
+
padding: "10px 20px",
|
|
3864
|
+
backgroundColor: "#007bff",
|
|
3865
|
+
color: "white",
|
|
3866
|
+
border: "none",
|
|
3867
|
+
borderRadius: "8px",
|
|
3868
|
+
fontSize: "14px",
|
|
3869
|
+
fontWeight: 600,
|
|
3870
|
+
cursor: "pointer"
|
|
3871
|
+
},
|
|
3872
|
+
children: "Update Name"
|
|
3873
|
+
}
|
|
3874
|
+
)
|
|
3875
|
+
] })
|
|
3876
|
+
] }),
|
|
3877
|
+
showAvatar && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
3878
|
+
padding: "20px",
|
|
3879
|
+
backgroundColor: "#fff",
|
|
3880
|
+
borderRadius: "8px",
|
|
3881
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
|
|
3882
|
+
marginBottom: "20px"
|
|
3883
|
+
}, children: [
|
|
3884
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Update Avatar" }),
|
|
3885
|
+
/* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleUpdateAvatar, children: [
|
|
3886
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3887
|
+
"input",
|
|
3888
|
+
{
|
|
3889
|
+
type: "url",
|
|
3890
|
+
value: avatar,
|
|
3891
|
+
onChange: (e) => setAvatar(e.target.value),
|
|
3892
|
+
required: true,
|
|
3893
|
+
disabled: isLoading,
|
|
3894
|
+
style: {
|
|
3895
|
+
width: "100%",
|
|
3896
|
+
padding: "12px 16px",
|
|
3897
|
+
border: "1px solid #ddd",
|
|
3898
|
+
borderRadius: "8px",
|
|
3899
|
+
fontSize: "16px",
|
|
3900
|
+
boxSizing: "border-box",
|
|
3901
|
+
marginBottom: "12px"
|
|
3902
|
+
},
|
|
3903
|
+
placeholder: "Avatar URL"
|
|
3904
|
+
}
|
|
3905
|
+
),
|
|
3906
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3907
|
+
"button",
|
|
3908
|
+
{
|
|
3909
|
+
type: "submit",
|
|
3910
|
+
disabled: isLoading,
|
|
3911
|
+
style: {
|
|
3912
|
+
padding: "10px 20px",
|
|
3913
|
+
backgroundColor: "#007bff",
|
|
3914
|
+
color: "white",
|
|
3915
|
+
border: "none",
|
|
3916
|
+
borderRadius: "8px",
|
|
3917
|
+
fontSize: "14px",
|
|
3918
|
+
fontWeight: 600,
|
|
3919
|
+
cursor: "pointer"
|
|
3920
|
+
},
|
|
3921
|
+
children: "Update Avatar"
|
|
3922
|
+
}
|
|
3923
|
+
)
|
|
3924
|
+
] })
|
|
3925
|
+
] }),
|
|
3926
|
+
showEmailChange && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
3927
|
+
padding: "20px",
|
|
3928
|
+
backgroundColor: "#fff",
|
|
3929
|
+
borderRadius: "8px",
|
|
3930
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
|
|
3931
|
+
marginBottom: "20px"
|
|
3932
|
+
}, children: [
|
|
3933
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Change Email" }),
|
|
3934
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { style: { fontSize: "14px", color: "#666", marginBottom: "12px" }, children: [
|
|
3935
|
+
"Current email: ",
|
|
3936
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: user.email })
|
|
3937
|
+
] }),
|
|
3938
|
+
/* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleRequestEmailChange, children: [
|
|
3939
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3940
|
+
"input",
|
|
3941
|
+
{
|
|
3942
|
+
type: "email",
|
|
3943
|
+
value: newEmail,
|
|
3944
|
+
onChange: (e) => setNewEmail(e.target.value),
|
|
3945
|
+
required: true,
|
|
3946
|
+
disabled: isLoading,
|
|
3947
|
+
style: {
|
|
3948
|
+
width: "100%",
|
|
3949
|
+
padding: "12px 16px",
|
|
3950
|
+
border: "1px solid #ddd",
|
|
3951
|
+
borderRadius: "8px",
|
|
3952
|
+
fontSize: "16px",
|
|
3953
|
+
boxSizing: "border-box",
|
|
3954
|
+
marginBottom: "12px"
|
|
3955
|
+
},
|
|
3956
|
+
placeholder: "New email address"
|
|
3957
|
+
}
|
|
3958
|
+
),
|
|
3959
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3960
|
+
"button",
|
|
3961
|
+
{
|
|
3962
|
+
type: "submit",
|
|
3963
|
+
disabled: isLoading,
|
|
3964
|
+
style: {
|
|
3965
|
+
padding: "10px 20px",
|
|
3966
|
+
backgroundColor: "#007bff",
|
|
3967
|
+
color: "white",
|
|
3968
|
+
border: "none",
|
|
3969
|
+
borderRadius: "8px",
|
|
3970
|
+
fontSize: "14px",
|
|
3971
|
+
fontWeight: 600,
|
|
3972
|
+
cursor: "pointer"
|
|
3973
|
+
},
|
|
3974
|
+
children: "Request Email Change"
|
|
3975
|
+
}
|
|
3976
|
+
)
|
|
3977
|
+
] })
|
|
3978
|
+
] })
|
|
3979
|
+
] });
|
|
3980
|
+
};
|
|
3981
|
+
|
|
3982
|
+
// src/react/index.ts
|
|
3983
|
+
var react_exports = {};
|
|
3984
|
+
__export(react_exports, {
|
|
3985
|
+
AuthFlow: () => AuthFlow,
|
|
3986
|
+
AuthProvider: () => AuthProvider,
|
|
3987
|
+
ChangePassword: () => ChangePassword,
|
|
3988
|
+
EmailVerificationPage: () => EmailVerificationPage,
|
|
3989
|
+
ForgotPassword: () => ForgotPassword,
|
|
3990
|
+
LoginForm: () => LoginForm,
|
|
3991
|
+
OtpForm: () => OtpForm,
|
|
3992
|
+
ProtectedRoute: () => ProtectedRoute,
|
|
3993
|
+
PublicRoute: () => PublicRoute,
|
|
3994
|
+
RegisterForm: () => RegisterForm,
|
|
3995
|
+
ResetPassword: () => ResetPassword,
|
|
3996
|
+
SignIn: () => SignIn,
|
|
3997
|
+
SignOut: () => SignOut,
|
|
3998
|
+
SignUp: () => SignUp,
|
|
3999
|
+
UserButton: () => UserButton,
|
|
4000
|
+
UserProfile: () => UserProfile,
|
|
4001
|
+
VerifyEmail: () => VerifyEmail,
|
|
4002
|
+
useAuth: () => useAuth,
|
|
4003
|
+
useAuthLegacy: () => useAuth2
|
|
4004
|
+
});
|
|
1763
4005
|
|
|
1764
4006
|
// src/node/index.ts
|
|
1765
4007
|
var node_exports = {};
|
|
@@ -1775,11 +4017,11 @@ var AuthClient = class extends AuthService {
|
|
|
1775
4017
|
// Override methods that require browser-specific features
|
|
1776
4018
|
// For Node.js, token persistence must be handled manually
|
|
1777
4019
|
async register(data) {
|
|
1778
|
-
const
|
|
1779
|
-
if (
|
|
1780
|
-
|
|
4020
|
+
const frontendBaseUrl = process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL;
|
|
4021
|
+
if (frontendBaseUrl) {
|
|
4022
|
+
this["httpClient"].setFrontendBaseUrl(frontendBaseUrl);
|
|
1781
4023
|
}
|
|
1782
|
-
const response = await this["httpClient"].post("/api/v1/auth/register",
|
|
4024
|
+
const response = await this["httpClient"].post("/api/v1/auth/register", data);
|
|
1783
4025
|
if (response.success && response.message === "Registration data saved. Verification email sent. Please check your inbox.") {
|
|
1784
4026
|
return response;
|
|
1785
4027
|
}
|
|
@@ -1845,9 +4087,27 @@ var AuthClient = class extends AuthService {
|
|
|
1845
4087
|
}
|
|
1846
4088
|
};
|
|
1847
4089
|
|
|
4090
|
+
exports.AuthFlow = AuthFlow;
|
|
4091
|
+
exports.AuthProvider = AuthProvider;
|
|
1848
4092
|
exports.AuthService = AuthService;
|
|
4093
|
+
exports.ChangePassword = ChangePassword;
|
|
4094
|
+
exports.EmailVerificationPage = EmailVerificationPage;
|
|
4095
|
+
exports.ForgotPassword = ForgotPassword;
|
|
1849
4096
|
exports.HttpClient = HttpClient;
|
|
4097
|
+
exports.LoginForm = LoginForm;
|
|
4098
|
+
exports.OtpForm = OtpForm;
|
|
4099
|
+
exports.ProtectedRoute = ProtectedRoute;
|
|
4100
|
+
exports.PublicRoute = PublicRoute;
|
|
4101
|
+
exports.RegisterForm = RegisterForm;
|
|
4102
|
+
exports.ResetPassword = ResetPassword;
|
|
4103
|
+
exports.SignIn = SignIn;
|
|
4104
|
+
exports.SignOut = SignOut;
|
|
4105
|
+
exports.SignUp = SignUp;
|
|
4106
|
+
exports.UserButton = UserButton;
|
|
4107
|
+
exports.UserProfile = UserProfile;
|
|
4108
|
+
exports.VerifyEmail = VerifyEmail;
|
|
1850
4109
|
exports.node = node_exports;
|
|
1851
4110
|
exports.react = react_exports;
|
|
4111
|
+
exports.useAuth = useAuth;
|
|
1852
4112
|
//# sourceMappingURL=out.js.map
|
|
1853
4113
|
//# sourceMappingURL=index.js.map
|