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