@thetechfossil/auth2 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1853 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var axios__default = /*#__PURE__*/_interopDefault(axios);
10
+
11
+ var __defProp = Object.defineProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var HttpClient = class {
17
+ constructor(baseUrl, defaultHeaders = {}) {
18
+ this.csrfToken = null;
19
+ this.axiosInstance = axios__default.default.create({
20
+ baseURL: baseUrl.replace(/\/$/, ""),
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ ...defaultHeaders
24
+ },
25
+ withCredentials: true,
26
+ // Include cookies for CSRF
27
+ timeout: 3e4
28
+ // 30 second timeout
29
+ });
30
+ this.axiosInstance.interceptors.request.use(
31
+ (config) => {
32
+ if (this.csrfToken && ["post", "put", "delete", "patch"].includes(config.method?.toLowerCase() || "")) {
33
+ config.headers["x-csrf-token"] = this.csrfToken;
34
+ }
35
+ return config;
36
+ },
37
+ (error) => Promise.reject(error)
38
+ );
39
+ this.axiosInstance.interceptors.response.use(
40
+ (response) => response,
41
+ async (error) => {
42
+ const originalRequest = error.config;
43
+ if (error.response?.status === 403 && !originalRequest._retry) {
44
+ originalRequest._retry = true;
45
+ try {
46
+ await this.refreshCsrfToken();
47
+ if (originalRequest.headers) {
48
+ originalRequest.headers["x-csrf-token"] = this.csrfToken;
49
+ }
50
+ return this.axiosInstance(originalRequest);
51
+ } catch (refreshError) {
52
+ return Promise.reject(refreshError);
53
+ }
54
+ }
55
+ return Promise.reject(error);
56
+ }
57
+ );
58
+ }
59
+ async get(endpoint, headers) {
60
+ const response = await this.axiosInstance.get(endpoint, { headers });
61
+ return response.data;
62
+ }
63
+ async post(endpoint, data, headers) {
64
+ const response = await this.axiosInstance.post(endpoint, data, { headers });
65
+ return response.data;
66
+ }
67
+ async put(endpoint, data, headers) {
68
+ const response = await this.axiosInstance.put(endpoint, data, { headers });
69
+ return response.data;
70
+ }
71
+ async delete(endpoint, headers) {
72
+ const response = await this.axiosInstance.delete(endpoint, { headers });
73
+ return response.data;
74
+ }
75
+ setAuthToken(token) {
76
+ this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
77
+ }
78
+ removeAuthToken() {
79
+ delete this.axiosInstance.defaults.headers.common["Authorization"];
80
+ }
81
+ setCsrfToken(token) {
82
+ this.csrfToken = token;
83
+ }
84
+ getCsrfToken() {
85
+ return this.csrfToken;
86
+ }
87
+ removeCsrfToken() {
88
+ this.csrfToken = null;
89
+ }
90
+ async refreshCsrfToken() {
91
+ try {
92
+ const response = await this.axiosInstance.get("/api/v1/auth/csrf-token");
93
+ this.csrfToken = response.data.csrfToken;
94
+ } catch (error) {
95
+ console.error("Failed to refresh CSRF token:", error);
96
+ throw error;
97
+ }
98
+ }
99
+ };
100
+
101
+ // src/core/auth-service.ts
102
+ var AuthService = class {
103
+ constructor(config) {
104
+ this.token = null;
105
+ this.config = {
106
+ localStorageKey: "auth_token",
107
+ csrfEnabled: true,
108
+ ...config
109
+ };
110
+ this.httpClient = new HttpClient(this.config.baseUrl);
111
+ this.loadTokenFromStorage();
112
+ if (this.config.csrfEnabled && typeof window !== "undefined") {
113
+ this.refreshCsrfToken();
114
+ }
115
+ }
116
+ loadTokenFromStorage() {
117
+ if (typeof window !== "undefined" && this.config.localStorageKey) {
118
+ try {
119
+ const token = localStorage.getItem(this.config.localStorageKey);
120
+ if (token) {
121
+ this.token = token;
122
+ this.httpClient.setAuthToken(token);
123
+ }
124
+ } catch (error) {
125
+ console.warn("Failed to load token from storage:", error);
126
+ }
127
+ }
128
+ }
129
+ saveTokenToStorage(token) {
130
+ if (typeof window !== "undefined" && this.config.localStorageKey) {
131
+ try {
132
+ localStorage.setItem(this.config.localStorageKey, token);
133
+ } catch (error) {
134
+ console.warn("Failed to save token to storage:", error);
135
+ }
136
+ }
137
+ }
138
+ removeTokenFromStorage() {
139
+ if (typeof window !== "undefined" && this.config.localStorageKey) {
140
+ try {
141
+ localStorage.removeItem(this.config.localStorageKey);
142
+ } catch (error) {
143
+ console.warn("Failed to remove token from storage:", error);
144
+ }
145
+ }
146
+ }
147
+ isAuthenticated() {
148
+ return !!this.token;
149
+ }
150
+ getToken() {
151
+ return this.token;
152
+ }
153
+ getCurrentUser() {
154
+ if (!this.token)
155
+ return null;
156
+ try {
157
+ const payload = JSON.parse(atob(this.token.split(".")[1]));
158
+ return payload.user || null;
159
+ } catch (error) {
160
+ console.error("Failed to parse user from token:", error);
161
+ return null;
162
+ }
163
+ }
164
+ // CSRF Token Management
165
+ async refreshCsrfToken() {
166
+ if (!this.config.csrfEnabled)
167
+ return;
168
+ try {
169
+ const response = await this.httpClient.get("/api/v1/auth/csrf-token");
170
+ if (response.csrfToken) {
171
+ this.httpClient.setCsrfToken(response.csrfToken);
172
+ }
173
+ } catch (error) {
174
+ console.error("Failed to get CSRF token:", error);
175
+ }
176
+ }
177
+ getCsrfToken() {
178
+ return this.httpClient.getCsrfToken();
179
+ }
180
+ // OAuth Methods
181
+ loginWithOAuth(provider) {
182
+ if (typeof window === "undefined") {
183
+ throw new Error("OAuth login is only available in browser environments");
184
+ }
185
+ const oauthUrl = `${this.config.baseUrl}/api/v1/auth/oauth/${provider}`;
186
+ window.location.href = oauthUrl;
187
+ }
188
+ linkOAuthProvider(provider) {
189
+ if (typeof window === "undefined") {
190
+ throw new Error("OAuth linking is only available in browser environments");
191
+ }
192
+ if (!this.token) {
193
+ throw new Error("Must be authenticated to link OAuth provider");
194
+ }
195
+ const linkUrl = `${this.config.baseUrl}/api/v1/auth/oauth/${provider}/link`;
196
+ window.location.href = linkUrl;
197
+ }
198
+ async unlinkOAuthProvider(provider) {
199
+ if (!this.token) {
200
+ throw new Error("Not authenticated");
201
+ }
202
+ const response = await this.httpClient.delete(
203
+ `/api/v1/auth/oauth/${provider}/unlink`
204
+ );
205
+ return response;
206
+ }
207
+ // Standard Auth Methods
208
+ async login(data) {
209
+ const response = await this.httpClient.post("/api/v1/auth/login", data);
210
+ if (response.success && response.token) {
211
+ this.token = response.token;
212
+ this.httpClient.setAuthToken(response.token);
213
+ this.saveTokenToStorage(response.token);
214
+ return response;
215
+ }
216
+ if (response.success && response.message === "OTP sent to your email.") {
217
+ return response;
218
+ }
219
+ if (response.success && response.message === "OTP verified successfully." && response.token) {
220
+ this.token = response.token;
221
+ this.httpClient.setAuthToken(response.token);
222
+ this.saveTokenToStorage(response.token);
223
+ return response;
224
+ }
225
+ throw new Error(response.message || "Login failed");
226
+ }
227
+ async register(data) {
228
+ const registerData = { ...data };
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);
233
+ if (response.success && response.message === "Registration data saved. Verification email sent. Please check your inbox.") {
234
+ return response;
235
+ }
236
+ throw new Error(response.message || "Registration failed");
237
+ }
238
+ async verify(data) {
239
+ const response = await this.httpClient.post("/api/v1/auth/verify", data);
240
+ if (response.success && response.token) {
241
+ this.token = response.token;
242
+ this.httpClient.setAuthToken(response.token);
243
+ this.saveTokenToStorage(response.token);
244
+ }
245
+ return response;
246
+ }
247
+ async verifyEmailToken(token) {
248
+ const response = await this.httpClient.get(`/api/v1/auth/verify-email?token=${token}`);
249
+ if (response.success && response.token) {
250
+ this.token = response.token;
251
+ this.httpClient.setAuthToken(response.token);
252
+ this.saveTokenToStorage(response.token);
253
+ }
254
+ return response;
255
+ }
256
+ async logout() {
257
+ this.token = null;
258
+ this.httpClient.removeAuthToken();
259
+ this.httpClient.removeCsrfToken();
260
+ this.removeTokenFromStorage();
261
+ }
262
+ async getProfile() {
263
+ if (!this.token) {
264
+ throw new Error("Not authenticated");
265
+ }
266
+ const response = await this.httpClient.get("/api/v1/user/me");
267
+ return response.user;
268
+ }
269
+ async updateProfile(data) {
270
+ if (!this.token) {
271
+ throw new Error("Not authenticated");
272
+ }
273
+ const response = await this.httpClient.post("/api/v1/user/update/user", data);
274
+ if (response.success && response.token) {
275
+ this.token = response.token;
276
+ this.httpClient.setAuthToken(response.token);
277
+ this.saveTokenToStorage(response.token);
278
+ }
279
+ return response;
280
+ }
281
+ async getAllUsers() {
282
+ if (!this.token) {
283
+ throw new Error("Not authenticated");
284
+ }
285
+ const response = await this.httpClient.get("/api/v1/user/all");
286
+ return response.users;
287
+ }
288
+ async getUserById(id) {
289
+ const response = await this.httpClient.get(`/api/v1/user/${id}`);
290
+ return response.user;
291
+ }
292
+ 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
+ const response = await this.httpClient.post("/api/v1/auth/forgot-password", { email });
297
+ return response;
298
+ }
299
+ async resetPassword(token, password) {
300
+ const response = await this.httpClient.post("/api/v1/auth/reset-password", { token, password });
301
+ return response;
302
+ }
303
+ };
304
+
305
+ // src/react/index.ts
306
+ var react_exports = {};
307
+ __export(react_exports, {
308
+ AuthFlow: () => AuthFlow,
309
+ EmailVerificationPage: () => EmailVerificationPage,
310
+ LoginForm: () => LoginForm,
311
+ OtpForm: () => OtpForm,
312
+ RegisterForm: () => RegisterForm,
313
+ useAuth: () => useAuth
314
+ });
315
+ var useAuth = (config) => {
316
+ const [authService] = react.useState(() => new AuthService(config));
317
+ const [user, setUser] = react.useState(null);
318
+ const [isAuthenticated, setIsAuthenticated] = react.useState(false);
319
+ const [loading, setLoading] = react.useState(true);
320
+ const checkAuthStatus = react.useCallback(() => {
321
+ const authenticated = authService.isAuthenticated();
322
+ setIsAuthenticated(authenticated);
323
+ if (authenticated) {
324
+ const currentUser = authService.getCurrentUser();
325
+ setUser(currentUser);
326
+ } else {
327
+ setUser(null);
328
+ }
329
+ setLoading(false);
330
+ }, [authService]);
331
+ react.useEffect(() => {
332
+ checkAuthStatus();
333
+ }, [checkAuthStatus]);
334
+ const register = react.useCallback(async (data) => {
335
+ setLoading(true);
336
+ try {
337
+ const registerData = { ...data };
338
+ if (!registerData.frontendBaseUrl && typeof window !== "undefined") {
339
+ registerData.frontendBaseUrl = process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
340
+ }
341
+ const response = await authService.register(registerData);
342
+ return response;
343
+ } finally {
344
+ setLoading(false);
345
+ }
346
+ }, [authService]);
347
+ const login = react.useCallback(async (data) => {
348
+ setLoading(true);
349
+ try {
350
+ const response = await authService.login(data);
351
+ if (response.success && response.user) {
352
+ setUser(response.user);
353
+ setIsAuthenticated(true);
354
+ }
355
+ return response;
356
+ } finally {
357
+ setLoading(false);
358
+ }
359
+ }, [authService]);
360
+ const verify = react.useCallback(async (data) => {
361
+ setLoading(true);
362
+ try {
363
+ const response = await authService.verify(data);
364
+ if (response.success && response.user) {
365
+ setUser(response.user);
366
+ setIsAuthenticated(true);
367
+ }
368
+ return response;
369
+ } finally {
370
+ setLoading(false);
371
+ }
372
+ }, [authService]);
373
+ const verifyEmailToken = react.useCallback(async (token) => {
374
+ setLoading(true);
375
+ try {
376
+ const response = await authService.verifyEmailToken(token);
377
+ if (response.success && response.user) {
378
+ setUser(response.user);
379
+ setIsAuthenticated(true);
380
+ }
381
+ return response;
382
+ } finally {
383
+ setLoading(false);
384
+ }
385
+ }, [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
+ const updateProfile = react.useCallback(async (data) => {
397
+ setLoading(true);
398
+ try {
399
+ const response = await authService.updateProfile(data);
400
+ if (response.success && response.user) {
401
+ setUser(response.user);
402
+ }
403
+ return response;
404
+ } finally {
405
+ setLoading(false);
406
+ }
407
+ }, [authService]);
408
+ const getProfile = react.useCallback(async () => {
409
+ setLoading(true);
410
+ try {
411
+ const userData = await authService.getProfile();
412
+ setUser(userData);
413
+ return userData;
414
+ } finally {
415
+ setLoading(false);
416
+ }
417
+ }, [authService]);
418
+ const getAllUsers = react.useCallback(async () => {
419
+ setLoading(true);
420
+ try {
421
+ return await authService.getAllUsers();
422
+ } finally {
423
+ setLoading(false);
424
+ }
425
+ }, [authService]);
426
+ const getUserById = react.useCallback(async (id) => {
427
+ setLoading(true);
428
+ try {
429
+ return await authService.getUserById(id);
430
+ } finally {
431
+ setLoading(false);
432
+ }
433
+ }, [authService]);
434
+ return {
435
+ user,
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);
472
+ try {
473
+ let response;
474
+ if (usePassword) {
475
+ response = await login({ email, password });
476
+ } else {
477
+ response = await login({ email });
478
+ }
479
+ if (response.success) {
480
+ onSuccess?.(response);
481
+ if (onLoginSuccess) {
482
+ if (response.message === "OTP sent to your email.") {
483
+ onLoginSuccess(email, true);
484
+ } else if (response.token) {
485
+ onLoginSuccess(email, false);
486
+ } else {
487
+ onLoginSuccess(email, true);
488
+ }
489
+ }
490
+ } else {
491
+ setError(response.message || "Login failed");
492
+ }
493
+ } catch (err) {
494
+ setError(err instanceof Error ? err.message : "An unknown error occurred");
495
+ } finally {
496
+ setIsLoading(false);
497
+ }
498
+ };
499
+ const toggleAuthMethod = () => {
500
+ setUsePassword(!usePassword);
501
+ setError(null);
502
+ };
503
+ const togglePasswordVisibility = () => {
504
+ setShowPassword(!showPassword);
505
+ };
506
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
507
+ maxWidth: "400px",
508
+ margin: "0 auto",
509
+ padding: "30px",
510
+ borderRadius: "12px",
511
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
512
+ backgroundColor: "#ffffff",
513
+ border: "1px solid #eaeaea"
514
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, style: {
515
+ display: "flex",
516
+ flexDirection: "column"
517
+ }, children: [
518
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
519
+ textAlign: "center",
520
+ marginBottom: "24px",
521
+ color: "#1f2937",
522
+ fontSize: "24px",
523
+ fontWeight: 600
524
+ }, children: usePassword ? "Login with Password" : "Login with OTP" }),
525
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
526
+ padding: "12px 16px",
527
+ marginBottom: "20px",
528
+ backgroundColor: "#f8d7da",
529
+ color: "#721c24",
530
+ border: "1px solid #f5c6cb",
531
+ borderRadius: "8px",
532
+ fontSize: "14px",
533
+ fontWeight: 500
534
+ }, children: error }),
535
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
536
+ marginBottom: "20px"
537
+ }, children: [
538
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
539
+ display: "block",
540
+ marginBottom: "8px",
541
+ fontWeight: 500,
542
+ color: "#374151",
543
+ fontSize: "14px"
544
+ }, children: "Email:" }),
545
+ /* @__PURE__ */ jsxRuntime.jsx(
546
+ "input",
547
+ {
548
+ id: "email",
549
+ type: "email",
550
+ value: email,
551
+ onChange: (e) => setEmail(e.target.value),
552
+ required: true,
553
+ disabled: isLoading,
554
+ style: {
555
+ width: "100%",
556
+ padding: "12px 16px",
557
+ border: "1px solid #ddd",
558
+ borderRadius: "8px",
559
+ fontSize: "16px",
560
+ boxSizing: "border-box",
561
+ color: "#111827",
562
+ transition: "all 0.2s ease",
563
+ backgroundColor: "#ffffff"
564
+ },
565
+ placeholder: "Enter your email"
566
+ }
567
+ )
568
+ ] }),
569
+ usePassword && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
570
+ marginBottom: "20px",
571
+ position: "relative"
572
+ }, children: [
573
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "login-password", style: {
574
+ display: "block",
575
+ marginBottom: "8px",
576
+ fontWeight: 500,
577
+ color: "#555",
578
+ fontSize: "14px"
579
+ }, children: "Password:" }),
580
+ /* @__PURE__ */ jsxRuntime.jsx(
581
+ "input",
582
+ {
583
+ id: "login-password",
584
+ type: showPassword ? "text" : "password",
585
+ value: password,
586
+ onChange: (e) => setPassword(e.target.value),
587
+ required: true,
588
+ disabled: isLoading,
589
+ style: {
590
+ width: "100%",
591
+ padding: "12px 16px",
592
+ border: "1px solid #ddd",
593
+ borderRadius: "8px",
594
+ fontSize: "16px",
595
+ boxSizing: "border-box",
596
+ color: "#333",
597
+ transition: "all 0.2s ease",
598
+ backgroundColor: "#fafafa"
599
+ },
600
+ placeholder: "Enter your password"
601
+ }
602
+ ),
603
+ /* @__PURE__ */ jsxRuntime.jsx(
604
+ "button",
605
+ {
606
+ type: "button",
607
+ onClick: togglePasswordVisibility,
608
+ disabled: isLoading,
609
+ style: {
610
+ position: "absolute",
611
+ right: "12px",
612
+ top: "38px",
613
+ background: "none",
614
+ border: "none",
615
+ cursor: "pointer",
616
+ color: "#666",
617
+ fontSize: "14px"
618
+ },
619
+ children: showPassword ? "Hide" : "Show"
620
+ }
621
+ )
622
+ ] }),
623
+ usePassword && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
624
+ display: "flex",
625
+ alignItems: "center",
626
+ marginBottom: "16px",
627
+ marginTop: "8px"
628
+ }, children: [
629
+ /* @__PURE__ */ jsxRuntime.jsx(
630
+ "input",
631
+ {
632
+ type: "checkbox",
633
+ id: "remember-me",
634
+ checked: rememberMe,
635
+ onChange: (e) => setRememberMe(e.target.checked),
636
+ disabled: isLoading,
637
+ style: {
638
+ marginRight: "8px",
639
+ cursor: "pointer",
640
+ width: "16px",
641
+ height: "16px"
642
+ }
643
+ }
644
+ ),
645
+ /* @__PURE__ */ jsxRuntime.jsx(
646
+ "label",
647
+ {
648
+ htmlFor: "remember-me",
649
+ style: {
650
+ fontSize: "14px",
651
+ color: "#666",
652
+ cursor: "pointer",
653
+ userSelect: "none"
654
+ },
655
+ children: "Remember me"
656
+ }
657
+ )
658
+ ] }),
659
+ /* @__PURE__ */ jsxRuntime.jsx(
660
+ "button",
661
+ {
662
+ type: "submit",
663
+ disabled: isLoading,
664
+ style: {
665
+ padding: "14px",
666
+ backgroundColor: "#007bff",
667
+ color: "white",
668
+ border: "none",
669
+ borderRadius: "8px",
670
+ fontSize: "16px",
671
+ fontWeight: 600,
672
+ cursor: "pointer",
673
+ transition: "all 0.2s ease",
674
+ marginTop: "8px"
675
+ },
676
+ children: isLoading ? usePassword ? "Logging in..." : "Sending OTP..." : usePassword ? "Login" : "Send OTP"
677
+ }
678
+ ),
679
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
680
+ textAlign: "center",
681
+ marginTop: "20px",
682
+ paddingTop: "20px",
683
+ borderTop: "1px solid #eee"
684
+ }, children: /* @__PURE__ */ jsxRuntime.jsx(
685
+ "button",
686
+ {
687
+ type: "button",
688
+ onClick: toggleAuthMethod,
689
+ disabled: isLoading,
690
+ style: {
691
+ background: "none",
692
+ border: "none",
693
+ color: "#007bff",
694
+ textDecoration: "none",
695
+ cursor: "pointer",
696
+ fontSize: "14px",
697
+ fontWeight: 600,
698
+ padding: "0",
699
+ transition: "color 0.2s ease"
700
+ },
701
+ children: usePassword ? "Login with OTP instead" : "Login with password instead"
702
+ }
703
+ ) }),
704
+ showOAuthButtons && oauthProviders.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
705
+ marginTop: "20px",
706
+ paddingTop: "20px",
707
+ borderTop: "1px solid #eee"
708
+ }, children: [
709
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
710
+ position: "relative",
711
+ marginBottom: "16px"
712
+ }, children: [
713
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
714
+ position: "absolute",
715
+ top: "50%",
716
+ left: 0,
717
+ right: 0,
718
+ height: "1px",
719
+ backgroundColor: "#eee"
720
+ } }),
721
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
722
+ position: "relative",
723
+ textAlign: "center"
724
+ }, children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
725
+ backgroundColor: "#ffffff",
726
+ padding: "0 12px",
727
+ color: "#666",
728
+ fontSize: "14px"
729
+ }, children: "Or continue with" }) })
730
+ ] }),
731
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
732
+ display: "grid",
733
+ gridTemplateColumns: oauthProviders.length === 1 ? "1fr" : "repeat(2, 1fr)",
734
+ gap: "12px"
735
+ }, children: [
736
+ oauthProviders.includes("google") && /* @__PURE__ */ jsxRuntime.jsxs(
737
+ "a",
738
+ {
739
+ href: `${config?.baseUrl || "http://localhost:7000"}/api/v1/auth/oauth/google`,
740
+ style: {
741
+ display: "flex",
742
+ alignItems: "center",
743
+ justifyContent: "center",
744
+ gap: "8px",
745
+ padding: "10px 16px",
746
+ backgroundColor: "#ffffff",
747
+ border: "1px solid #ddd",
748
+ borderRadius: "8px",
749
+ color: "#333",
750
+ textDecoration: "none",
751
+ fontSize: "14px",
752
+ fontWeight: 500,
753
+ cursor: "pointer",
754
+ transition: "all 0.2s ease"
755
+ },
756
+ onMouseEnter: (e) => {
757
+ e.currentTarget.style.backgroundColor = "#f8f8f8";
758
+ e.currentTarget.style.borderColor = "#007bff";
759
+ },
760
+ onMouseLeave: (e) => {
761
+ e.currentTarget.style.backgroundColor = "#ffffff";
762
+ e.currentTarget.style.borderColor = "#ddd";
763
+ },
764
+ children: [
765
+ /* @__PURE__ */ jsxRuntime.jsxs("svg", { style: { width: "18px", height: "18px" }, viewBox: "0 0 24 24", children: [
766
+ /* @__PURE__ */ jsxRuntime.jsx(
767
+ "path",
768
+ {
769
+ fill: "#4285F4",
770
+ d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
771
+ }
772
+ ),
773
+ /* @__PURE__ */ jsxRuntime.jsx(
774
+ "path",
775
+ {
776
+ fill: "#34A853",
777
+ d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
778
+ }
779
+ ),
780
+ /* @__PURE__ */ jsxRuntime.jsx(
781
+ "path",
782
+ {
783
+ fill: "#FBBC05",
784
+ d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
785
+ }
786
+ ),
787
+ /* @__PURE__ */ jsxRuntime.jsx(
788
+ "path",
789
+ {
790
+ fill: "#EA4335",
791
+ d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
792
+ }
793
+ )
794
+ ] }),
795
+ "Google"
796
+ ]
797
+ }
798
+ ),
799
+ oauthProviders.includes("github") && /* @__PURE__ */ jsxRuntime.jsxs(
800
+ "a",
801
+ {
802
+ href: `${config?.baseUrl || "http://localhost:7000"}/api/v1/auth/oauth/github`,
803
+ style: {
804
+ display: "flex",
805
+ alignItems: "center",
806
+ justifyContent: "center",
807
+ gap: "8px",
808
+ padding: "10px 16px",
809
+ backgroundColor: "#24292e",
810
+ border: "1px solid #24292e",
811
+ borderRadius: "8px",
812
+ color: "#ffffff",
813
+ textDecoration: "none",
814
+ fontSize: "14px",
815
+ fontWeight: 500,
816
+ cursor: "pointer",
817
+ transition: "all 0.2s ease"
818
+ },
819
+ onMouseEnter: (e) => {
820
+ e.currentTarget.style.backgroundColor = "#1b1f23";
821
+ e.currentTarget.style.borderColor = "#1b1f23";
822
+ },
823
+ onMouseLeave: (e) => {
824
+ e.currentTarget.style.backgroundColor = "#24292e";
825
+ e.currentTarget.style.borderColor = "#24292e";
826
+ },
827
+ children: [
828
+ /* @__PURE__ */ jsxRuntime.jsx("svg", { style: { width: "18px", height: "18px" }, fill: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" }) }),
829
+ "GitHub"
830
+ ]
831
+ }
832
+ )
833
+ ] })
834
+ ] }),
835
+ showRegisterLink && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
836
+ textAlign: "center",
837
+ marginTop: "20px",
838
+ paddingTop: "20px",
839
+ borderTop: "1px solid #eee"
840
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
841
+ color: "#666",
842
+ fontSize: "14px"
843
+ }, children: [
844
+ "Don't have an account?",
845
+ " ",
846
+ /* @__PURE__ */ jsxRuntime.jsx(
847
+ "button",
848
+ {
849
+ type: "button",
850
+ onClick: onRegisterClick,
851
+ disabled: isLoading,
852
+ style: {
853
+ background: "none",
854
+ border: "none",
855
+ color: "#007bff",
856
+ textDecoration: "none",
857
+ cursor: "pointer",
858
+ fontSize: "14px",
859
+ fontWeight: 600,
860
+ padding: "0",
861
+ transition: "color 0.2s ease"
862
+ },
863
+ children: "Register"
864
+ }
865
+ )
866
+ ] }) })
867
+ ] }) });
868
+ };
869
+ var RegisterForm = ({
870
+ onRegisterSuccess,
871
+ onLoginClick,
872
+ showLoginLink = true,
873
+ authConfig,
874
+ oauthProviders = ["google", "github"],
875
+ showOAuthButtons = true
876
+ }) => {
877
+ const [name, setName] = react.useState("");
878
+ const [email, setEmail] = react.useState("");
879
+ const [password, setPassword] = react.useState("");
880
+ const [confirmPassword, setConfirmPassword] = react.useState("");
881
+ const [isLoading, setIsLoading] = react.useState(false);
882
+ const [error, setError] = react.useState(null);
883
+ react.useState(false);
884
+ react.useState(false);
885
+ const getPasswordStrength = (pwd) => {
886
+ if (!pwd)
887
+ return { strength: "weak", score: 0, label: "" };
888
+ let score = 0;
889
+ if (pwd.length >= 6)
890
+ score++;
891
+ if (pwd.length >= 8)
892
+ score++;
893
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
894
+ score++;
895
+ if (/\d/.test(pwd))
896
+ score++;
897
+ if (/[^a-zA-Z\d]/.test(pwd))
898
+ score++;
899
+ if (score <= 2)
900
+ return { strength: "weak", score, label: "Weak" };
901
+ if (score <= 3)
902
+ return { strength: "medium", score, label: "Medium" };
903
+ return { strength: "strong", score, label: "Strong" };
904
+ };
905
+ getPasswordStrength(password);
906
+ const config = authConfig || {
907
+ baseUrl: typeof window !== "undefined" ? process.env.NEXT_PUBLIC_AUTH_API_URL || window.location.origin : "http://localhost:7000"
908
+ };
909
+ const { register } = useAuth(config);
910
+ const handleSubmit = async (e) => {
911
+ e.preventDefault();
912
+ setIsLoading(true);
913
+ setError(null);
914
+ if (password !== confirmPassword) {
915
+ setError("Passwords do not match");
916
+ setIsLoading(false);
917
+ return;
918
+ }
919
+ if (password.length < 6) {
920
+ setError("Password must be at least 6 characters long");
921
+ setIsLoading(false);
922
+ return;
923
+ }
924
+ try {
925
+ const registerData = {
926
+ name,
927
+ email,
928
+ password,
929
+ frontendBaseUrl: typeof window !== "undefined" ? process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || window.location.origin : void 0
930
+ };
931
+ const response = await register(registerData);
932
+ if (response.success) {
933
+ onRegisterSuccess?.();
934
+ } else {
935
+ setError(response.message || "Registration failed");
936
+ }
937
+ } catch (err) {
938
+ setError(err instanceof Error ? err.message : "An unknown error occurred");
939
+ } finally {
940
+ setIsLoading(false);
941
+ }
942
+ };
943
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
944
+ maxWidth: "400px",
945
+ margin: "0 auto",
946
+ padding: "30px",
947
+ borderRadius: "12px",
948
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
949
+ backgroundColor: "#ffffff",
950
+ border: "1px solid #eaeaea"
951
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, style: {
952
+ display: "flex",
953
+ flexDirection: "column"
954
+ }, children: [
955
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
956
+ textAlign: "center",
957
+ marginBottom: "24px",
958
+ color: "#1f2937",
959
+ fontSize: "24px",
960
+ fontWeight: 600
961
+ }, children: "Register" }),
962
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
963
+ padding: "12px 16px",
964
+ marginBottom: "20px",
965
+ backgroundColor: "#f8d7da",
966
+ color: "#721c24",
967
+ border: "1px solid #f5c6cb",
968
+ borderRadius: "8px",
969
+ fontSize: "14px",
970
+ fontWeight: 500
971
+ }, children: error }),
972
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
973
+ marginBottom: "20px"
974
+ }, children: [
975
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "name", style: {
976
+ display: "block",
977
+ marginBottom: "8px",
978
+ fontWeight: 500,
979
+ color: "#374151",
980
+ fontSize: "14px"
981
+ }, children: "Name:" }),
982
+ /* @__PURE__ */ jsxRuntime.jsx(
983
+ "input",
984
+ {
985
+ id: "name",
986
+ type: "text",
987
+ value: name,
988
+ onChange: (e) => setName(e.target.value),
989
+ required: true,
990
+ disabled: isLoading,
991
+ style: {
992
+ width: "100%",
993
+ padding: "12px 16px",
994
+ border: "1px solid #ddd",
995
+ borderRadius: "8px",
996
+ fontSize: "16px",
997
+ boxSizing: "border-box",
998
+ color: "#111827",
999
+ transition: "all 0.2s ease",
1000
+ backgroundColor: "#ffffff"
1001
+ },
1002
+ placeholder: "Enter your name"
1003
+ }
1004
+ )
1005
+ ] }),
1006
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1007
+ marginBottom: "20px"
1008
+ }, children: [
1009
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "register-email", style: {
1010
+ display: "block",
1011
+ marginBottom: "8px",
1012
+ fontWeight: 500,
1013
+ color: "#555",
1014
+ fontSize: "14px"
1015
+ }, children: "Email:" }),
1016
+ /* @__PURE__ */ jsxRuntime.jsx(
1017
+ "input",
1018
+ {
1019
+ id: "register-email",
1020
+ type: "email",
1021
+ value: email,
1022
+ onChange: (e) => setEmail(e.target.value),
1023
+ required: true,
1024
+ disabled: isLoading,
1025
+ style: {
1026
+ width: "100%",
1027
+ padding: "12px 16px",
1028
+ border: "1px solid #ddd",
1029
+ borderRadius: "8px",
1030
+ fontSize: "16px",
1031
+ boxSizing: "border-box",
1032
+ color: "#333",
1033
+ transition: "all 0.2s ease",
1034
+ backgroundColor: "#fafafa"
1035
+ },
1036
+ placeholder: "Enter your email"
1037
+ }
1038
+ )
1039
+ ] }),
1040
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1041
+ marginBottom: "20px"
1042
+ }, children: [
1043
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
1044
+ display: "block",
1045
+ marginBottom: "8px",
1046
+ fontWeight: 500,
1047
+ color: "#555",
1048
+ fontSize: "14px"
1049
+ }, children: "Password:" }),
1050
+ /* @__PURE__ */ jsxRuntime.jsx(
1051
+ "input",
1052
+ {
1053
+ id: "password",
1054
+ type: "password",
1055
+ value: password,
1056
+ onChange: (e) => setPassword(e.target.value),
1057
+ required: true,
1058
+ disabled: isLoading,
1059
+ style: {
1060
+ width: "100%",
1061
+ padding: "12px 16px",
1062
+ border: "1px solid #ddd",
1063
+ borderRadius: "8px",
1064
+ fontSize: "16px",
1065
+ boxSizing: "border-box",
1066
+ color: "#333",
1067
+ transition: "all 0.2s ease",
1068
+ backgroundColor: "#fafafa"
1069
+ },
1070
+ placeholder: "Enter your password",
1071
+ minLength: 6
1072
+ }
1073
+ )
1074
+ ] }),
1075
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1076
+ marginBottom: "20px"
1077
+ }, children: [
1078
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "confirm-password", style: {
1079
+ display: "block",
1080
+ marginBottom: "8px",
1081
+ fontWeight: 500,
1082
+ color: "#555",
1083
+ fontSize: "14px"
1084
+ }, children: "Confirm Password:" }),
1085
+ /* @__PURE__ */ jsxRuntime.jsx(
1086
+ "input",
1087
+ {
1088
+ id: "confirm-password",
1089
+ type: "password",
1090
+ value: confirmPassword,
1091
+ onChange: (e) => setConfirmPassword(e.target.value),
1092
+ required: true,
1093
+ disabled: isLoading,
1094
+ style: {
1095
+ width: "100%",
1096
+ padding: "12px 16px",
1097
+ border: "1px solid #ddd",
1098
+ borderRadius: "8px",
1099
+ fontSize: "16px",
1100
+ boxSizing: "border-box",
1101
+ color: "#333",
1102
+ transition: "all 0.2s ease",
1103
+ backgroundColor: "#fafafa"
1104
+ },
1105
+ placeholder: "Confirm your password"
1106
+ }
1107
+ )
1108
+ ] }),
1109
+ /* @__PURE__ */ jsxRuntime.jsx(
1110
+ "button",
1111
+ {
1112
+ type: "submit",
1113
+ disabled: isLoading,
1114
+ style: {
1115
+ padding: "14px",
1116
+ backgroundColor: "#007bff",
1117
+ color: "white",
1118
+ border: "none",
1119
+ borderRadius: "8px",
1120
+ fontSize: "16px",
1121
+ fontWeight: 600,
1122
+ cursor: "pointer",
1123
+ transition: "all 0.2s ease",
1124
+ marginTop: "8px"
1125
+ },
1126
+ children: isLoading ? "Registering..." : "Register"
1127
+ }
1128
+ ),
1129
+ showOAuthButtons && oauthProviders.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1130
+ marginTop: "20px",
1131
+ paddingTop: "20px",
1132
+ borderTop: "1px solid #eee"
1133
+ }, children: [
1134
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1135
+ position: "relative",
1136
+ marginBottom: "16px"
1137
+ }, children: [
1138
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1139
+ position: "absolute",
1140
+ top: "50%",
1141
+ left: 0,
1142
+ right: 0,
1143
+ height: "1px",
1144
+ backgroundColor: "#eee"
1145
+ } }),
1146
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1147
+ position: "relative",
1148
+ textAlign: "center"
1149
+ }, children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
1150
+ backgroundColor: "#ffffff",
1151
+ padding: "0 12px",
1152
+ color: "#666",
1153
+ fontSize: "14px"
1154
+ }, children: "Or continue with" }) })
1155
+ ] }),
1156
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1157
+ display: "grid",
1158
+ gridTemplateColumns: oauthProviders.length === 1 ? "1fr" : "repeat(2, 1fr)",
1159
+ gap: "12px"
1160
+ }, children: [
1161
+ oauthProviders.includes("google") && /* @__PURE__ */ jsxRuntime.jsxs(
1162
+ "a",
1163
+ {
1164
+ href: `${config.baseUrl}/api/v1/auth/oauth/google`,
1165
+ style: {
1166
+ display: "flex",
1167
+ alignItems: "center",
1168
+ justifyContent: "center",
1169
+ gap: "8px",
1170
+ padding: "10px 16px",
1171
+ backgroundColor: "#ffffff",
1172
+ border: "1px solid #ddd",
1173
+ borderRadius: "8px",
1174
+ color: "#333",
1175
+ textDecoration: "none",
1176
+ fontSize: "14px",
1177
+ fontWeight: 500,
1178
+ cursor: "pointer",
1179
+ transition: "all 0.2s ease"
1180
+ },
1181
+ onMouseEnter: (e) => {
1182
+ e.currentTarget.style.backgroundColor = "#f8f8f8";
1183
+ e.currentTarget.style.borderColor = "#007bff";
1184
+ },
1185
+ onMouseLeave: (e) => {
1186
+ e.currentTarget.style.backgroundColor = "#ffffff";
1187
+ e.currentTarget.style.borderColor = "#ddd";
1188
+ },
1189
+ children: [
1190
+ /* @__PURE__ */ jsxRuntime.jsxs("svg", { style: { width: "18px", height: "18px" }, viewBox: "0 0 24 24", children: [
1191
+ /* @__PURE__ */ jsxRuntime.jsx(
1192
+ "path",
1193
+ {
1194
+ fill: "#4285F4",
1195
+ d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
1196
+ }
1197
+ ),
1198
+ /* @__PURE__ */ jsxRuntime.jsx(
1199
+ "path",
1200
+ {
1201
+ fill: "#34A853",
1202
+ d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
1203
+ }
1204
+ ),
1205
+ /* @__PURE__ */ jsxRuntime.jsx(
1206
+ "path",
1207
+ {
1208
+ fill: "#FBBC05",
1209
+ d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
1210
+ }
1211
+ ),
1212
+ /* @__PURE__ */ jsxRuntime.jsx(
1213
+ "path",
1214
+ {
1215
+ fill: "#EA4335",
1216
+ d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
1217
+ }
1218
+ )
1219
+ ] }),
1220
+ "Google"
1221
+ ]
1222
+ }
1223
+ ),
1224
+ oauthProviders.includes("github") && /* @__PURE__ */ jsxRuntime.jsxs(
1225
+ "a",
1226
+ {
1227
+ href: `${config.baseUrl}/api/v1/auth/oauth/github`,
1228
+ style: {
1229
+ display: "flex",
1230
+ alignItems: "center",
1231
+ justifyContent: "center",
1232
+ gap: "8px",
1233
+ padding: "10px 16px",
1234
+ backgroundColor: "#24292e",
1235
+ border: "1px solid #24292e",
1236
+ borderRadius: "8px",
1237
+ color: "#ffffff",
1238
+ textDecoration: "none",
1239
+ fontSize: "14px",
1240
+ fontWeight: 500,
1241
+ cursor: "pointer",
1242
+ transition: "all 0.2s ease"
1243
+ },
1244
+ onMouseEnter: (e) => {
1245
+ e.currentTarget.style.backgroundColor = "#1b1f23";
1246
+ e.currentTarget.style.borderColor = "#1b1f23";
1247
+ },
1248
+ onMouseLeave: (e) => {
1249
+ e.currentTarget.style.backgroundColor = "#24292e";
1250
+ e.currentTarget.style.borderColor = "#24292e";
1251
+ },
1252
+ children: [
1253
+ /* @__PURE__ */ jsxRuntime.jsx("svg", { style: { width: "18px", height: "18px" }, fill: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" }) }),
1254
+ "GitHub"
1255
+ ]
1256
+ }
1257
+ )
1258
+ ] })
1259
+ ] }),
1260
+ showLoginLink && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1261
+ textAlign: "center",
1262
+ marginTop: "20px",
1263
+ paddingTop: "20px",
1264
+ borderTop: "1px solid #eee"
1265
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
1266
+ color: "#666",
1267
+ fontSize: "14px"
1268
+ }, children: [
1269
+ "Already have an account?",
1270
+ " ",
1271
+ /* @__PURE__ */ jsxRuntime.jsx(
1272
+ "button",
1273
+ {
1274
+ type: "button",
1275
+ onClick: onLoginClick,
1276
+ disabled: isLoading,
1277
+ style: {
1278
+ background: "none",
1279
+ border: "none",
1280
+ color: "#007bff",
1281
+ textDecoration: "none",
1282
+ cursor: "pointer",
1283
+ fontSize: "14px",
1284
+ fontWeight: 600,
1285
+ padding: "0",
1286
+ transition: "color 0.2s ease"
1287
+ },
1288
+ children: "Login"
1289
+ }
1290
+ )
1291
+ ] }) })
1292
+ ] }) });
1293
+ };
1294
+ var OtpForm = ({
1295
+ email,
1296
+ onVerifySuccess,
1297
+ onBackToLogin
1298
+ }) => {
1299
+ const [otp, setOtp] = react.useState("");
1300
+ const [isLoading, setIsLoading] = react.useState(false);
1301
+ const [error, setError] = react.useState(null);
1302
+ const [resendCooldown, setResendCooldown] = react.useState(0);
1303
+ const [resendLoading, setResendLoading] = react.useState(false);
1304
+ const { verify, login } = useAuth({
1305
+ baseUrl: typeof window !== "undefined" ? window.location.origin : "http://localhost:7000"
1306
+ });
1307
+ const handleSubmit = async (e) => {
1308
+ e.preventDefault();
1309
+ setIsLoading(true);
1310
+ setError(null);
1311
+ if (!/^\d{6}$/.test(otp)) {
1312
+ setError("Please enter a valid 6-digit OTP");
1313
+ setIsLoading(false);
1314
+ return;
1315
+ }
1316
+ try {
1317
+ const response = await verify({ email, otp });
1318
+ if (response.success) {
1319
+ onVerifySuccess?.();
1320
+ } else {
1321
+ setError(response.message || "Verification failed");
1322
+ }
1323
+ } catch (err) {
1324
+ setError(err instanceof Error ? err.message : "An unknown error occurred");
1325
+ } finally {
1326
+ setIsLoading(false);
1327
+ }
1328
+ };
1329
+ const handleOtpChange = (e) => {
1330
+ const value = e.target.value;
1331
+ if (/^\d{0,6}$/.test(value)) {
1332
+ setOtp(value);
1333
+ }
1334
+ };
1335
+ const handleResendOtp = async () => {
1336
+ if (resendCooldown > 0 || resendLoading)
1337
+ return;
1338
+ setResendLoading(true);
1339
+ setError(null);
1340
+ try {
1341
+ const response = await login({ email });
1342
+ if (response.success) {
1343
+ setResendCooldown(60);
1344
+ const interval = setInterval(() => {
1345
+ setResendCooldown((prev) => {
1346
+ if (prev <= 1) {
1347
+ clearInterval(interval);
1348
+ return 0;
1349
+ }
1350
+ return prev - 1;
1351
+ });
1352
+ }, 1e3);
1353
+ } else {
1354
+ setError(response.message || "Failed to resend OTP");
1355
+ }
1356
+ } catch (err) {
1357
+ setError(err instanceof Error ? err.message : "Failed to resend OTP");
1358
+ } finally {
1359
+ setResendLoading(false);
1360
+ }
1361
+ };
1362
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1363
+ maxWidth: "400px",
1364
+ margin: "0 auto",
1365
+ padding: "30px",
1366
+ borderRadius: "12px",
1367
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
1368
+ backgroundColor: "#ffffff",
1369
+ border: "1px solid #eaeaea"
1370
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, style: {
1371
+ display: "flex",
1372
+ flexDirection: "column"
1373
+ }, children: [
1374
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
1375
+ textAlign: "center",
1376
+ marginBottom: "24px",
1377
+ color: "#1f2937",
1378
+ fontSize: "24px",
1379
+ fontWeight: 600
1380
+ }, children: "Verify OTP" }),
1381
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
1382
+ textAlign: "center",
1383
+ marginBottom: "24px",
1384
+ color: "#4b5563",
1385
+ fontSize: "14px"
1386
+ }, children: [
1387
+ "Enter the 6-digit code sent to ",
1388
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { style: { color: "#111827" }, children: email })
1389
+ ] }),
1390
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1391
+ padding: "12px 16px",
1392
+ marginBottom: "20px",
1393
+ backgroundColor: "#f8d7da",
1394
+ color: "#721c24",
1395
+ border: "1px solid #f5c6cb",
1396
+ borderRadius: "8px",
1397
+ fontSize: "14px",
1398
+ fontWeight: 500
1399
+ }, children: error }),
1400
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1401
+ marginBottom: "20px"
1402
+ }, children: [
1403
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "otp", style: {
1404
+ display: "block",
1405
+ marginBottom: "8px",
1406
+ fontWeight: 500,
1407
+ color: "#374151",
1408
+ fontSize: "14px"
1409
+ }, children: "OTP Code:" }),
1410
+ /* @__PURE__ */ jsxRuntime.jsx(
1411
+ "input",
1412
+ {
1413
+ id: "otp",
1414
+ type: "text",
1415
+ value: otp,
1416
+ onChange: handleOtpChange,
1417
+ required: true,
1418
+ disabled: isLoading,
1419
+ style: {
1420
+ width: "100%",
1421
+ padding: "12px 16px",
1422
+ border: "1px solid #ddd",
1423
+ borderRadius: "8px",
1424
+ fontSize: "20px",
1425
+ boxSizing: "border-box",
1426
+ color: "#111827",
1427
+ transition: "all 0.2s ease",
1428
+ backgroundColor: "#ffffff",
1429
+ textAlign: "center",
1430
+ letterSpacing: "5px"
1431
+ },
1432
+ maxLength: 6,
1433
+ placeholder: "123456",
1434
+ autoFocus: true
1435
+ }
1436
+ )
1437
+ ] }),
1438
+ /* @__PURE__ */ jsxRuntime.jsx(
1439
+ "button",
1440
+ {
1441
+ type: "submit",
1442
+ disabled: isLoading || otp.length !== 6,
1443
+ style: {
1444
+ padding: "14px",
1445
+ backgroundColor: "#007bff",
1446
+ color: "white",
1447
+ border: "none",
1448
+ borderRadius: "8px",
1449
+ fontSize: "16px",
1450
+ fontWeight: 600,
1451
+ cursor: "pointer",
1452
+ transition: "all 0.2s ease",
1453
+ marginTop: "8px"
1454
+ },
1455
+ children: isLoading ? "Verifying..." : "Verify OTP"
1456
+ }
1457
+ ),
1458
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1459
+ textAlign: "center",
1460
+ marginTop: "20px",
1461
+ paddingTop: "20px",
1462
+ borderTop: "1px solid #eee"
1463
+ }, children: [
1464
+ /* @__PURE__ */ jsxRuntime.jsx(
1465
+ "button",
1466
+ {
1467
+ type: "button",
1468
+ onClick: handleResendOtp,
1469
+ disabled: isLoading || resendLoading || resendCooldown > 0,
1470
+ style: {
1471
+ background: "none",
1472
+ border: "none",
1473
+ color: resendCooldown > 0 ? "#999" : "#007bff",
1474
+ textDecoration: "none",
1475
+ cursor: resendCooldown > 0 ? "not-allowed" : "pointer",
1476
+ fontSize: "14px",
1477
+ fontWeight: 600,
1478
+ padding: "0",
1479
+ marginBottom: "12px",
1480
+ transition: "color 0.2s ease",
1481
+ display: "block",
1482
+ width: "100%"
1483
+ },
1484
+ children: resendLoading ? "Sending..." : resendCooldown > 0 ? `Resend OTP in ${resendCooldown}s` : "Resend OTP"
1485
+ }
1486
+ ),
1487
+ /* @__PURE__ */ jsxRuntime.jsx(
1488
+ "button",
1489
+ {
1490
+ type: "button",
1491
+ onClick: onBackToLogin,
1492
+ disabled: isLoading,
1493
+ style: {
1494
+ background: "none",
1495
+ border: "none",
1496
+ color: "#007bff",
1497
+ textDecoration: "none",
1498
+ cursor: "pointer",
1499
+ fontSize: "14px",
1500
+ fontWeight: 600,
1501
+ padding: "0",
1502
+ transition: "color 0.2s ease"
1503
+ },
1504
+ children: "Back to Login"
1505
+ }
1506
+ )
1507
+ ] })
1508
+ ] }) });
1509
+ };
1510
+ var AuthFlow = ({
1511
+ onAuthComplete,
1512
+ initialStep = "login",
1513
+ showTitle = true
1514
+ }) => {
1515
+ const [step, setStep] = react.useState(initialStep);
1516
+ const [email, setEmail] = react.useState("");
1517
+ const [message, setMessage] = react.useState(null);
1518
+ const handleLoginSuccess = (email2, needsOtpVerification) => {
1519
+ setEmail(email2);
1520
+ if (needsOtpVerification) {
1521
+ setStep("otp");
1522
+ setMessage(null);
1523
+ } else {
1524
+ setMessage(null);
1525
+ onAuthComplete?.();
1526
+ }
1527
+ };
1528
+ const handleRegisterSuccess = () => {
1529
+ setMessage("Registration successful! Please check your email for verification.");
1530
+ setTimeout(() => {
1531
+ setStep("login");
1532
+ setMessage(null);
1533
+ }, 3e3);
1534
+ };
1535
+ const handleVerifySuccess = () => {
1536
+ setMessage(null);
1537
+ onAuthComplete?.();
1538
+ };
1539
+ const handleBackToLogin = () => {
1540
+ setStep("login");
1541
+ setMessage(null);
1542
+ };
1543
+ const renderCurrentStep = () => {
1544
+ switch (step) {
1545
+ case "login":
1546
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1547
+ showTitle && /* @__PURE__ */ jsxRuntime.jsx("h1", { style: {
1548
+ textAlign: "center",
1549
+ marginBottom: "24px",
1550
+ color: "#333",
1551
+ fontSize: "32px",
1552
+ fontWeight: 700
1553
+ }, children: "Welcome Back" }),
1554
+ message && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1555
+ padding: "12px 16px",
1556
+ marginBottom: "20px",
1557
+ backgroundColor: "#d4edda",
1558
+ color: "#155724",
1559
+ border: "1px solid #c3e6cb",
1560
+ borderRadius: "8px",
1561
+ fontSize: "14px",
1562
+ fontWeight: 500
1563
+ }, children: message }),
1564
+ /* @__PURE__ */ jsxRuntime.jsx(
1565
+ LoginForm,
1566
+ {
1567
+ onLoginSuccess: handleLoginSuccess,
1568
+ onRegisterClick: () => setStep("register"),
1569
+ showRegisterLink: true
1570
+ }
1571
+ )
1572
+ ] });
1573
+ case "register":
1574
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1575
+ showTitle && /* @__PURE__ */ jsxRuntime.jsx("h1", { style: {
1576
+ textAlign: "center",
1577
+ marginBottom: "24px",
1578
+ color: "#333",
1579
+ fontSize: "32px",
1580
+ fontWeight: 700
1581
+ }, children: "Create Account" }),
1582
+ message && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1583
+ padding: "12px 16px",
1584
+ marginBottom: "20px",
1585
+ backgroundColor: "#d4edda",
1586
+ color: "#155724",
1587
+ border: "1px solid #c3e6cb",
1588
+ borderRadius: "8px",
1589
+ fontSize: "14px",
1590
+ fontWeight: 500
1591
+ }, children: message }),
1592
+ /* @__PURE__ */ jsxRuntime.jsx(
1593
+ RegisterForm,
1594
+ {
1595
+ onRegisterSuccess: handleRegisterSuccess,
1596
+ onLoginClick: () => setStep("login"),
1597
+ showLoginLink: true
1598
+ }
1599
+ )
1600
+ ] });
1601
+ case "otp":
1602
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1603
+ showTitle && /* @__PURE__ */ jsxRuntime.jsx("h1", { style: {
1604
+ textAlign: "center",
1605
+ marginBottom: "24px",
1606
+ color: "#333",
1607
+ fontSize: "32px",
1608
+ fontWeight: 700
1609
+ }, children: "Verify Your Email" }),
1610
+ /* @__PURE__ */ jsxRuntime.jsx(
1611
+ OtpForm,
1612
+ {
1613
+ email,
1614
+ onVerifySuccess: handleVerifySuccess,
1615
+ onBackToLogin: handleBackToLogin
1616
+ }
1617
+ )
1618
+ ] });
1619
+ default:
1620
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1621
+ showTitle && /* @__PURE__ */ jsxRuntime.jsx("h1", { style: {
1622
+ textAlign: "center",
1623
+ marginBottom: "24px",
1624
+ color: "#333",
1625
+ fontSize: "32px",
1626
+ fontWeight: 700
1627
+ }, children: "Welcome Back" }),
1628
+ /* @__PURE__ */ jsxRuntime.jsx(
1629
+ LoginForm,
1630
+ {
1631
+ onLoginSuccess: handleLoginSuccess,
1632
+ onRegisterClick: () => setStep("register"),
1633
+ showRegisterLink: true
1634
+ }
1635
+ )
1636
+ ] });
1637
+ }
1638
+ };
1639
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1640
+ minHeight: "300px",
1641
+ display: "flex",
1642
+ alignItems: "center",
1643
+ justifyContent: "center"
1644
+ }, children: renderCurrentStep() });
1645
+ };
1646
+ var EmailVerificationPage = ({
1647
+ token,
1648
+ onVerificationSuccess,
1649
+ onVerificationError,
1650
+ baseUrl
1651
+ }) => {
1652
+ const [isLoading, setIsLoading] = react.useState(true);
1653
+ const [message, setMessage] = react.useState("");
1654
+ const [isSuccess, setIsSuccess] = react.useState(false);
1655
+ const { verifyEmailToken } = useAuth({
1656
+ baseUrl: baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
1657
+ });
1658
+ react.useEffect(() => {
1659
+ const verifyEmail = async () => {
1660
+ if (!token) {
1661
+ setIsLoading(false);
1662
+ setMessage("Invalid verification token");
1663
+ setIsSuccess(false);
1664
+ onVerificationError?.("Invalid verification token");
1665
+ return;
1666
+ }
1667
+ try {
1668
+ const response = await verifyEmailToken(token);
1669
+ if (response.success) {
1670
+ setIsLoading(false);
1671
+ setMessage(response.message || "Email verified successfully!");
1672
+ setIsSuccess(true);
1673
+ onVerificationSuccess?.();
1674
+ } else {
1675
+ setIsLoading(false);
1676
+ setMessage(response.message || "Email verification failed");
1677
+ setIsSuccess(false);
1678
+ onVerificationError?.(response.message || "Email verification failed");
1679
+ }
1680
+ } catch (err) {
1681
+ setIsLoading(false);
1682
+ const errorMessage = err instanceof Error ? err.message : "An unknown error occurred";
1683
+ setMessage(errorMessage);
1684
+ setIsSuccess(false);
1685
+ onVerificationError?.(errorMessage);
1686
+ }
1687
+ };
1688
+ verifyEmail();
1689
+ }, [token, verifyEmailToken, onVerificationSuccess, onVerificationError]);
1690
+ if (isLoading) {
1691
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1692
+ maxWidth: "500px",
1693
+ margin: "0 auto",
1694
+ padding: "30px",
1695
+ borderRadius: "12px",
1696
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
1697
+ backgroundColor: "#ffffff",
1698
+ textAlign: "center",
1699
+ border: "1px solid #eaeaea"
1700
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1701
+ padding: "20px"
1702
+ }, children: [
1703
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: { color: "black" }, children: "Verifying your email..." }),
1704
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1705
+ border: "4px solid #f3f3f3",
1706
+ borderTop: "4px solid #007bff",
1707
+ borderRadius: "50%",
1708
+ width: "40px",
1709
+ height: "40px",
1710
+ animation: "spin 2s linear infinite",
1711
+ margin: "20px auto"
1712
+ } })
1713
+ ] }) });
1714
+ }
1715
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1716
+ maxWidth: "500px",
1717
+ margin: "0 auto",
1718
+ padding: "30px",
1719
+ borderRadius: "12px",
1720
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
1721
+ backgroundColor: "#ffffff",
1722
+ textAlign: "center",
1723
+ border: "1px solid #eaeaea"
1724
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1725
+ padding: "20px"
1726
+ }, children: [
1727
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: { color: "black" }, children: "Email Verification" }),
1728
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1729
+ padding: "16px 20px",
1730
+ margin: "24px 0",
1731
+ borderRadius: "8px",
1732
+ fontSize: "15px",
1733
+ fontWeight: 500,
1734
+ backgroundColor: isSuccess ? "#d4edda" : "#f8d7da",
1735
+ color: isSuccess ? "#155724" : "#721c24",
1736
+ border: isSuccess ? "1px solid #c3e6cb" : "1px solid #f5c6cb"
1737
+ }, children: message }),
1738
+ isSuccess && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1739
+ marginTop: "24px"
1740
+ }, children: [
1741
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "black" }, children: "Your email has been successfully verified!" }),
1742
+ /* @__PURE__ */ jsxRuntime.jsx(
1743
+ "button",
1744
+ {
1745
+ onClick: () => window.location.href = "/login",
1746
+ style: {
1747
+ padding: "12px 24px",
1748
+ backgroundColor: "#007bff",
1749
+ color: "white",
1750
+ border: "none",
1751
+ borderRadius: "8px",
1752
+ fontSize: "16px",
1753
+ fontWeight: 600,
1754
+ cursor: "pointer",
1755
+ transition: "all 0.2s ease"
1756
+ },
1757
+ children: "Go to Login"
1758
+ }
1759
+ )
1760
+ ] })
1761
+ ] }) });
1762
+ };
1763
+
1764
+ // src/node/index.ts
1765
+ var node_exports = {};
1766
+ __export(node_exports, {
1767
+ AuthClient: () => AuthClient
1768
+ });
1769
+
1770
+ // src/node/auth-client.ts
1771
+ var AuthClient = class extends AuthService {
1772
+ constructor(config) {
1773
+ super(config);
1774
+ }
1775
+ // Override methods that require browser-specific features
1776
+ // For Node.js, token persistence must be handled manually
1777
+ async register(data) {
1778
+ const registerData = { ...data };
1779
+ if (!registerData.frontendBaseUrl) {
1780
+ registerData.frontendBaseUrl = process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL;
1781
+ }
1782
+ const response = await this["httpClient"].post("/api/v1/auth/register", registerData);
1783
+ if (response.success && response.message === "Registration data saved. Verification email sent. Please check your inbox.") {
1784
+ return response;
1785
+ }
1786
+ throw new Error(response.message || "Registration failed");
1787
+ }
1788
+ async login(data) {
1789
+ const response = await this["httpClient"].post("/api/v1/auth/login", data);
1790
+ if (response.success && response.token) {
1791
+ this["token"] = response.token;
1792
+ this["httpClient"].setAuthToken(response.token);
1793
+ return response;
1794
+ }
1795
+ if (response.success && response.message === "OTP sent to your email.") {
1796
+ return response;
1797
+ }
1798
+ if (response.success && response.message === "OTP verified successfully." && response.token) {
1799
+ this["token"] = response.token;
1800
+ this["httpClient"].setAuthToken(response.token);
1801
+ return response;
1802
+ }
1803
+ throw new Error(response.message || "Login failed");
1804
+ }
1805
+ async verify(data) {
1806
+ const response = await this["httpClient"].post("/api/v1/auth/verify", data);
1807
+ if (response.success && response.token) {
1808
+ this["token"] = response.token;
1809
+ this["httpClient"].setAuthToken(response.token);
1810
+ }
1811
+ return response;
1812
+ }
1813
+ async logout() {
1814
+ this["token"] = null;
1815
+ this["httpClient"].removeAuthToken();
1816
+ }
1817
+ async getProfile() {
1818
+ if (!this["token"]) {
1819
+ throw new Error("Not authenticated");
1820
+ }
1821
+ const response = await this["httpClient"].get("/api/v1/user/me");
1822
+ return response.user;
1823
+ }
1824
+ async getUserById(id) {
1825
+ const response = await this["httpClient"].get(`/api/v1/user/${id}`);
1826
+ return response.user;
1827
+ }
1828
+ async updateProfile(data) {
1829
+ if (!this["token"]) {
1830
+ throw new Error("Not authenticated");
1831
+ }
1832
+ const response = await this["httpClient"].post("/api/v1/user/update/name", data);
1833
+ if (response.success && response.token) {
1834
+ this["token"] = response.token;
1835
+ this["httpClient"].setAuthToken(response.token);
1836
+ }
1837
+ return response;
1838
+ }
1839
+ async getAllUsers() {
1840
+ if (!this["token"]) {
1841
+ throw new Error("Not authenticated");
1842
+ }
1843
+ const response = await this["httpClient"].get("/api/v1/user/all");
1844
+ return response.users;
1845
+ }
1846
+ };
1847
+
1848
+ exports.AuthService = AuthService;
1849
+ exports.HttpClient = HttpClient;
1850
+ exports.node = node_exports;
1851
+ exports.react = react_exports;
1852
+ //# sourceMappingURL=out.js.map
1853
+ //# sourceMappingURL=index.js.map