@thetechfossil/auth2 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,7 @@ var axios__default = /*#__PURE__*/_interopDefault(axios);
12
12
  var HttpClient = class {
13
13
  constructor(baseUrl, defaultHeaders = {}) {
14
14
  this.csrfToken = null;
15
+ this.frontendBaseUrl = null;
15
16
  this.axiosInstance = axios__default.default.create({
16
17
  baseURL: baseUrl.replace(/\/$/, ""),
17
18
  headers: {
@@ -28,6 +29,9 @@ var HttpClient = class {
28
29
  if (this.csrfToken && ["post", "put", "delete", "patch"].includes(config.method?.toLowerCase() || "")) {
29
30
  config.headers["x-csrf-token"] = this.csrfToken;
30
31
  }
32
+ if (this.frontendBaseUrl) {
33
+ config.headers["X-Frontend-URL"] = this.frontendBaseUrl;
34
+ }
31
35
  return config;
32
36
  },
33
37
  (error) => Promise.reject(error)
@@ -83,6 +87,15 @@ var HttpClient = class {
83
87
  removeCsrfToken() {
84
88
  this.csrfToken = null;
85
89
  }
90
+ setFrontendBaseUrl(url) {
91
+ this.frontendBaseUrl = url;
92
+ }
93
+ getFrontendBaseUrl() {
94
+ return this.frontendBaseUrl;
95
+ }
96
+ removeFrontendBaseUrl() {
97
+ this.frontendBaseUrl = null;
98
+ }
86
99
  async refreshCsrfToken() {
87
100
  try {
88
101
  const response = await this.axiosInstance.get("/api/v1/auth/csrf-token");
@@ -105,6 +118,12 @@ var AuthService = class {
105
118
  };
106
119
  this.httpClient = new HttpClient(this.config.baseUrl);
107
120
  this.loadTokenFromStorage();
121
+ if (typeof window !== "undefined") {
122
+ 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;
123
+ if (frontendBaseUrl) {
124
+ this.httpClient.setFrontendBaseUrl(frontendBaseUrl);
125
+ }
126
+ }
108
127
  if (this.config.csrfEnabled && typeof window !== "undefined") {
109
128
  this.refreshCsrfToken();
110
129
  }
@@ -221,11 +240,7 @@ var AuthService = class {
221
240
  throw new Error(response.message || "Login failed");
222
241
  }
223
242
  async register(data) {
224
- const registerData = { ...data };
225
- if (!registerData.frontendBaseUrl && typeof window !== "undefined") {
226
- 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;
227
- }
228
- const response = await this.httpClient.post("/api/v1/auth/register", registerData);
243
+ const response = await this.httpClient.post("/api/v1/auth/register", data);
229
244
  if (response.success && response.message === "Registration data saved. Verification email sent. Please check your inbox.") {
230
245
  return response;
231
246
  }
@@ -241,15 +256,33 @@ var AuthService = class {
241
256
  return response;
242
257
  }
243
258
  async verifyEmailToken(token) {
244
- const response = await this.httpClient.get(`/api/v1/auth/verify-email?token=${token}`);
245
- if (response.success && response.token) {
246
- this.token = response.token;
247
- this.httpClient.setAuthToken(response.token);
248
- this.saveTokenToStorage(response.token);
259
+ try {
260
+ const response = await this.httpClient.get(`/api/v1/auth/verify-email?token=${token}`);
261
+ if (response.success && response.token) {
262
+ this.token = response.token;
263
+ this.httpClient.setAuthToken(response.token);
264
+ this.saveTokenToStorage(response.token);
265
+ }
266
+ return response;
267
+ } catch (error) {
268
+ if (error.response?.data) {
269
+ return {
270
+ success: false,
271
+ message: error.response.data.message || "Email verification failed"
272
+ };
273
+ }
274
+ return {
275
+ success: false,
276
+ message: error.message || "Network error occurred"
277
+ };
249
278
  }
250
- return response;
251
279
  }
252
280
  async logout() {
281
+ try {
282
+ await this.httpClient.post("/api/v1/auth/logout", {});
283
+ } catch (error) {
284
+ console.warn("Failed to call logout endpoint:", error);
285
+ }
253
286
  this.token = null;
254
287
  this.httpClient.removeAuthToken();
255
288
  this.httpClient.removeCsrfToken();
@@ -286,9 +319,6 @@ var AuthService = class {
286
319
  return response.user;
287
320
  }
288
321
  async forgotPassword(email) {
289
- if (typeof window !== "undefined") {
290
- 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;
291
- }
292
322
  const response = await this.httpClient.post("/api/v1/auth/forgot-password", { email });
293
323
  return response;
294
324
  }
@@ -296,6 +326,142 @@ var AuthService = class {
296
326
  const response = await this.httpClient.post("/api/v1/auth/reset-password", { token, password });
297
327
  return response;
298
328
  }
329
+ async changePassword(oldPassword, newPassword) {
330
+ if (!this.token) {
331
+ throw new Error("Not authenticated");
332
+ }
333
+ const response = await this.httpClient.post("/api/v1/user/change-password", {
334
+ oldPassword,
335
+ newPassword
336
+ });
337
+ return response;
338
+ }
339
+ async updateAvatar(avatar) {
340
+ if (!this.token) {
341
+ throw new Error("Not authenticated");
342
+ }
343
+ const response = await this.httpClient.post("/api/v1/user/update/avatar", { avatar });
344
+ if (response.success && response.token) {
345
+ this.token = response.token;
346
+ this.httpClient.setAuthToken(response.token);
347
+ this.saveTokenToStorage(response.token);
348
+ }
349
+ return response;
350
+ }
351
+ async requestEmailChange(newEmail) {
352
+ if (!this.token) {
353
+ throw new Error("Not authenticated");
354
+ }
355
+ const response = await this.httpClient.post("/api/v1/user/request-email-change", {
356
+ newEmail
357
+ });
358
+ return response;
359
+ }
360
+ async verifyEmailChange(token) {
361
+ const response = await this.httpClient.get(`/api/v1/user/verify-email-change?token=${token}`);
362
+ if (response.success && response.token) {
363
+ this.token = response.token;
364
+ this.httpClient.setAuthToken(response.token);
365
+ this.saveTokenToStorage(response.token);
366
+ }
367
+ return response;
368
+ }
369
+ // 2FA / MFA Methods
370
+ async generate2FA() {
371
+ if (!this.token) {
372
+ throw new Error("Not authenticated");
373
+ }
374
+ const response = await this.httpClient.post(
375
+ "/api/v1/mfa/generate",
376
+ {}
377
+ );
378
+ return response;
379
+ }
380
+ async enable2FA(token) {
381
+ if (!this.token) {
382
+ throw new Error("Not authenticated");
383
+ }
384
+ const response = await this.httpClient.post("/api/v1/mfa/enable", { token });
385
+ return response;
386
+ }
387
+ async disable2FA(token) {
388
+ if (!this.token) {
389
+ throw new Error("Not authenticated");
390
+ }
391
+ const response = await this.httpClient.post("/api/v1/mfa/disable", { token });
392
+ return response;
393
+ }
394
+ async validate2FA(token) {
395
+ if (!this.token) {
396
+ throw new Error("Not authenticated");
397
+ }
398
+ const response = await this.httpClient.post("/api/v1/mfa/validate", { token });
399
+ return response;
400
+ }
401
+ // Session Management Methods
402
+ async getSessions() {
403
+ if (!this.token) {
404
+ throw new Error("Not authenticated");
405
+ }
406
+ const response = await this.httpClient.get("/api/v1/session");
407
+ return response;
408
+ }
409
+ async revokeSession(sessionId) {
410
+ if (!this.token) {
411
+ throw new Error("Not authenticated");
412
+ }
413
+ const response = await this.httpClient.delete(`/api/v1/session/${sessionId}`);
414
+ return response;
415
+ }
416
+ async revokeAllSessions() {
417
+ if (!this.token) {
418
+ throw new Error("Not authenticated");
419
+ }
420
+ const response = await this.httpClient.delete("/api/v1/session/revoke/all");
421
+ this.token = null;
422
+ this.httpClient.removeAuthToken();
423
+ this.removeTokenFromStorage();
424
+ return response;
425
+ }
426
+ // Admin Methods
427
+ async getAuditLogs(filters) {
428
+ if (!this.token) {
429
+ throw new Error("Not authenticated");
430
+ }
431
+ const response = await this.httpClient.get(
432
+ "/api/v1/admin/audit-logs",
433
+ filters
434
+ );
435
+ return response;
436
+ }
437
+ async adminVerifyUser(userId) {
438
+ if (!this.token) {
439
+ throw new Error("Not authenticated");
440
+ }
441
+ const response = await this.httpClient.post(`/api/v1/admin/verify-user/${userId}`, {});
442
+ return response;
443
+ }
444
+ async adminForcePasswordReset(userId) {
445
+ if (!this.token) {
446
+ throw new Error("Not authenticated");
447
+ }
448
+ const response = await this.httpClient.post(`/api/v1/admin/force-password-reset/${userId}`, {});
449
+ return response;
450
+ }
451
+ async adminSuspendUser(userId) {
452
+ if (!this.token) {
453
+ throw new Error("Not authenticated");
454
+ }
455
+ const response = await this.httpClient.post(`/api/v1/admin/suspend-user/${userId}`, {});
456
+ return response;
457
+ }
458
+ async adminActivateUser(userId) {
459
+ if (!this.token) {
460
+ throw new Error("Not authenticated");
461
+ }
462
+ const response = await this.httpClient.post(`/api/v1/admin/activate-user/${userId}`, {});
463
+ return response;
464
+ }
299
465
  };
300
466
 
301
467
  // src/react/use-auth.ts
@@ -321,11 +487,7 @@ var useAuth = (config) => {
321
487
  const register = react.useCallback(async (data) => {
322
488
  setLoading(true);
323
489
  try {
324
- const registerData = { ...data };
325
- if (!registerData.frontendBaseUrl && typeof window !== "undefined") {
326
- 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;
327
- }
328
- const response = await authService.register(registerData);
490
+ const response = await authService.register(data);
329
491
  return response;
330
492
  } finally {
331
493
  setLoading(false);
@@ -1747,11 +1909,1825 @@ var EmailVerificationPage = ({
1747
1909
  ] })
1748
1910
  ] }) });
1749
1911
  };
1912
+ var AuthContext = react.createContext(void 0);
1913
+ var useAuth2 = () => {
1914
+ const context = react.useContext(AuthContext);
1915
+ if (context === void 0) {
1916
+ throw new Error("useAuth must be used within an AuthProvider");
1917
+ }
1918
+ return context;
1919
+ };
1920
+ var SignIn = ({ redirectUrl, appearance }) => {
1921
+ const { signIn, isSignedIn, loading: authLoading } = useAuth2();
1922
+ const [email, setEmail] = react.useState("");
1923
+ const [password, setPassword] = react.useState("");
1924
+ const [otp, setOtp] = react.useState("");
1925
+ const [usePassword, setUsePassword] = react.useState(false);
1926
+ const [showPassword, setShowPassword] = react.useState(false);
1927
+ const [isLoading, setIsLoading] = react.useState(false);
1928
+ const [error, setError] = react.useState(null);
1929
+ const [needsOtp, setNeedsOtp] = react.useState(false);
1930
+ const [success, setSuccess] = react.useState(null);
1931
+ react.useEffect(() => {
1932
+ if (isSignedIn && redirectUrl) {
1933
+ const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
1934
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
1935
+ window.location.href = `${baseUrl}${redirect}`;
1936
+ }
1937
+ }, [isSignedIn, redirectUrl]);
1938
+ const handleSubmit = async (e) => {
1939
+ e.preventDefault();
1940
+ setIsLoading(true);
1941
+ setError(null);
1942
+ setSuccess(null);
1943
+ try {
1944
+ if (needsOtp) {
1945
+ const response = await signIn({ email, otp });
1946
+ if (response.success) {
1947
+ setSuccess("Login successful!");
1948
+ } else {
1949
+ setError(response.message || "OTP verification failed");
1950
+ }
1951
+ } else if (usePassword) {
1952
+ const response = await signIn({ email, password });
1953
+ if (response.success) {
1954
+ setSuccess("Login successful!");
1955
+ } else {
1956
+ setError(response.message || "Login failed");
1957
+ }
1958
+ } else {
1959
+ const response = await signIn({ email });
1960
+ if (response.success && response.message === "OTP sent to your email.") {
1961
+ setNeedsOtp(true);
1962
+ setSuccess("OTP sent to your email. Please check your inbox.");
1963
+ } else {
1964
+ setError(response.message || "Failed to send OTP");
1965
+ }
1966
+ }
1967
+ } catch (err) {
1968
+ setError(err instanceof Error ? err.message : "An error occurred");
1969
+ } finally {
1970
+ setIsLoading(false);
1971
+ }
1972
+ };
1973
+ const toggleAuthMethod = () => {
1974
+ setUsePassword(!usePassword);
1975
+ setNeedsOtp(false);
1976
+ setError(null);
1977
+ setSuccess(null);
1978
+ setOtp("");
1979
+ };
1980
+ if (authLoading) {
1981
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }) });
1982
+ }
1983
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1984
+ maxWidth: "400px",
1985
+ margin: "0 auto",
1986
+ padding: "30px",
1987
+ borderRadius: "12px",
1988
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
1989
+ backgroundColor: "#ffffff",
1990
+ border: "1px solid #eaeaea",
1991
+ ...appearance?.elements?.card
1992
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
1993
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
1994
+ textAlign: "center",
1995
+ marginBottom: "24px",
1996
+ color: "#1f2937",
1997
+ fontSize: "24px",
1998
+ fontWeight: 600,
1999
+ ...appearance?.elements?.headerTitle
2000
+ }, children: needsOtp ? "Enter OTP" : usePassword ? "Sign in with password" : "Sign in" }),
2001
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2002
+ padding: "12px 16px",
2003
+ marginBottom: "20px",
2004
+ backgroundColor: "#fee",
2005
+ color: "#c33",
2006
+ border: "1px solid #fcc",
2007
+ borderRadius: "8px",
2008
+ fontSize: "14px"
2009
+ }, children: error }),
2010
+ success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2011
+ padding: "12px 16px",
2012
+ marginBottom: "20px",
2013
+ backgroundColor: "#efe",
2014
+ color: "#3c3",
2015
+ border: "1px solid #cfc",
2016
+ borderRadius: "8px",
2017
+ fontSize: "14px"
2018
+ }, children: success }),
2019
+ !needsOtp && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
2020
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
2021
+ display: "block",
2022
+ marginBottom: "8px",
2023
+ fontWeight: 500,
2024
+ color: "#374151",
2025
+ fontSize: "14px"
2026
+ }, children: "Email" }),
2027
+ /* @__PURE__ */ jsxRuntime.jsx(
2028
+ "input",
2029
+ {
2030
+ id: "email",
2031
+ type: "email",
2032
+ value: email,
2033
+ onChange: (e) => setEmail(e.target.value),
2034
+ required: true,
2035
+ disabled: isLoading,
2036
+ style: {
2037
+ width: "100%",
2038
+ padding: "12px 16px",
2039
+ border: "1px solid #ddd",
2040
+ borderRadius: "8px",
2041
+ fontSize: "16px",
2042
+ boxSizing: "border-box",
2043
+ ...appearance?.elements?.formFieldInput
2044
+ },
2045
+ placeholder: "Enter your email"
2046
+ }
2047
+ )
2048
+ ] }),
2049
+ usePassword && !needsOtp && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
2050
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
2051
+ display: "block",
2052
+ marginBottom: "8px",
2053
+ fontWeight: 500,
2054
+ color: "#374151",
2055
+ fontSize: "14px"
2056
+ }, children: "Password" }),
2057
+ /* @__PURE__ */ jsxRuntime.jsx(
2058
+ "input",
2059
+ {
2060
+ id: "password",
2061
+ type: showPassword ? "text" : "password",
2062
+ value: password,
2063
+ onChange: (e) => setPassword(e.target.value),
2064
+ required: true,
2065
+ disabled: isLoading,
2066
+ style: {
2067
+ width: "100%",
2068
+ padding: "12px 16px",
2069
+ border: "1px solid #ddd",
2070
+ borderRadius: "8px",
2071
+ fontSize: "16px",
2072
+ boxSizing: "border-box",
2073
+ ...appearance?.elements?.formFieldInput
2074
+ },
2075
+ placeholder: "Enter your password"
2076
+ }
2077
+ ),
2078
+ /* @__PURE__ */ jsxRuntime.jsx(
2079
+ "button",
2080
+ {
2081
+ type: "button",
2082
+ onClick: () => setShowPassword(!showPassword),
2083
+ style: {
2084
+ position: "absolute",
2085
+ right: "12px",
2086
+ top: "38px",
2087
+ background: "none",
2088
+ border: "none",
2089
+ cursor: "pointer",
2090
+ color: "#666",
2091
+ fontSize: "14px"
2092
+ },
2093
+ children: showPassword ? "Hide" : "Show"
2094
+ }
2095
+ )
2096
+ ] }),
2097
+ needsOtp && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
2098
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "otp", style: {
2099
+ display: "block",
2100
+ marginBottom: "8px",
2101
+ fontWeight: 500,
2102
+ color: "#374151",
2103
+ fontSize: "14px"
2104
+ }, children: "One-Time Password" }),
2105
+ /* @__PURE__ */ jsxRuntime.jsx(
2106
+ "input",
2107
+ {
2108
+ id: "otp",
2109
+ type: "text",
2110
+ value: otp,
2111
+ onChange: (e) => setOtp(e.target.value),
2112
+ required: true,
2113
+ disabled: isLoading,
2114
+ maxLength: 6,
2115
+ style: {
2116
+ width: "100%",
2117
+ padding: "12px 16px",
2118
+ border: "1px solid #ddd",
2119
+ borderRadius: "8px",
2120
+ fontSize: "16px",
2121
+ boxSizing: "border-box",
2122
+ letterSpacing: "0.5em",
2123
+ textAlign: "center",
2124
+ ...appearance?.elements?.formFieldInput
2125
+ },
2126
+ placeholder: "000000"
2127
+ }
2128
+ )
2129
+ ] }),
2130
+ /* @__PURE__ */ jsxRuntime.jsx(
2131
+ "button",
2132
+ {
2133
+ type: "submit",
2134
+ disabled: isLoading,
2135
+ style: {
2136
+ width: "100%",
2137
+ padding: "14px",
2138
+ backgroundColor: "#007bff",
2139
+ color: "white",
2140
+ border: "none",
2141
+ borderRadius: "8px",
2142
+ fontSize: "16px",
2143
+ fontWeight: 600,
2144
+ cursor: "pointer",
2145
+ transition: "all 0.2s ease",
2146
+ ...appearance?.elements?.formButtonPrimary
2147
+ },
2148
+ children: isLoading ? "Please wait..." : needsOtp ? "Verify OTP" : usePassword ? "Sign in" : "Continue with email"
2149
+ }
2150
+ ),
2151
+ !needsOtp && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", marginTop: "16px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
2152
+ "button",
2153
+ {
2154
+ type: "button",
2155
+ onClick: toggleAuthMethod,
2156
+ disabled: isLoading,
2157
+ style: {
2158
+ background: "none",
2159
+ border: "none",
2160
+ color: "#007bff",
2161
+ cursor: "pointer",
2162
+ fontSize: "14px",
2163
+ fontWeight: 600
2164
+ },
2165
+ children: usePassword ? "Use email code instead" : "Use password instead"
2166
+ }
2167
+ ) }),
2168
+ needsOtp && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", marginTop: "16px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
2169
+ "button",
2170
+ {
2171
+ type: "button",
2172
+ onClick: () => {
2173
+ setNeedsOtp(false);
2174
+ setOtp("");
2175
+ setError(null);
2176
+ setSuccess(null);
2177
+ },
2178
+ disabled: isLoading,
2179
+ style: {
2180
+ background: "none",
2181
+ border: "none",
2182
+ color: "#007bff",
2183
+ cursor: "pointer",
2184
+ fontSize: "14px",
2185
+ fontWeight: 600
2186
+ },
2187
+ children: "Back to sign in"
2188
+ }
2189
+ ) })
2190
+ ] }) });
2191
+ };
2192
+ var SignUp = ({ redirectUrl, appearance }) => {
2193
+ const { signUp, isSignedIn } = useAuth2();
2194
+ const [name, setName] = react.useState("");
2195
+ const [email, setEmail] = react.useState("");
2196
+ const [password, setPassword] = react.useState("");
2197
+ const [confirmPassword, setConfirmPassword] = react.useState("");
2198
+ const [showPassword, setShowPassword] = react.useState(false);
2199
+ const [isLoading, setIsLoading] = react.useState(false);
2200
+ const [error, setError] = react.useState(null);
2201
+ const [success, setSuccess] = react.useState(null);
2202
+ react.useEffect(() => {
2203
+ if (isSignedIn && redirectUrl) {
2204
+ const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_AFTER_REGISTER || "/dashboard";
2205
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2206
+ window.location.href = `${baseUrl}${redirect}`;
2207
+ }
2208
+ }, [isSignedIn, redirectUrl]);
2209
+ const getPasswordStrength = (pwd) => {
2210
+ if (!pwd)
2211
+ return { strength: "weak", color: "#ddd" };
2212
+ let score = 0;
2213
+ if (pwd.length >= 6)
2214
+ score++;
2215
+ if (pwd.length >= 8)
2216
+ score++;
2217
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
2218
+ score++;
2219
+ if (/\d/.test(pwd))
2220
+ score++;
2221
+ if (/[^a-zA-Z\d]/.test(pwd))
2222
+ score++;
2223
+ if (score <= 2)
2224
+ return { strength: "weak", color: "#f44" };
2225
+ if (score <= 3)
2226
+ return { strength: "medium", color: "#fa4" };
2227
+ return { strength: "strong", color: "#4f4" };
2228
+ };
2229
+ const passwordStrength = getPasswordStrength(password);
2230
+ const handleSubmit = async (e) => {
2231
+ e.preventDefault();
2232
+ setIsLoading(true);
2233
+ setError(null);
2234
+ setSuccess(null);
2235
+ if (password !== confirmPassword) {
2236
+ setError("Passwords do not match");
2237
+ setIsLoading(false);
2238
+ return;
2239
+ }
2240
+ if (password.length < 6) {
2241
+ setError("Password must be at least 6 characters");
2242
+ setIsLoading(false);
2243
+ return;
2244
+ }
2245
+ try {
2246
+ const response = await signUp({ name, email, password });
2247
+ if (response.success) {
2248
+ setSuccess("Registration successful! Please check your email to verify your account.");
2249
+ } else {
2250
+ setError(response.message || "Registration failed");
2251
+ }
2252
+ } catch (err) {
2253
+ setError(err instanceof Error ? err.message : "An error occurred");
2254
+ } finally {
2255
+ setIsLoading(false);
2256
+ }
2257
+ };
2258
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2259
+ maxWidth: "400px",
2260
+ margin: "0 auto",
2261
+ padding: "30px",
2262
+ borderRadius: "12px",
2263
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
2264
+ backgroundColor: "#ffffff",
2265
+ border: "1px solid #eaeaea",
2266
+ ...appearance?.elements?.card
2267
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
2268
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
2269
+ textAlign: "center",
2270
+ marginBottom: "24px",
2271
+ color: "#1f2937",
2272
+ fontSize: "24px",
2273
+ fontWeight: 600,
2274
+ ...appearance?.elements?.headerTitle
2275
+ }, children: "Create your account" }),
2276
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2277
+ padding: "12px 16px",
2278
+ marginBottom: "20px",
2279
+ backgroundColor: "#fee",
2280
+ color: "#c33",
2281
+ border: "1px solid #fcc",
2282
+ borderRadius: "8px",
2283
+ fontSize: "14px"
2284
+ }, children: error }),
2285
+ success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2286
+ padding: "12px 16px",
2287
+ marginBottom: "20px",
2288
+ backgroundColor: "#efe",
2289
+ color: "#3c3",
2290
+ border: "1px solid #cfc",
2291
+ borderRadius: "8px",
2292
+ fontSize: "14px"
2293
+ }, children: success }),
2294
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
2295
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "name", style: {
2296
+ display: "block",
2297
+ marginBottom: "8px",
2298
+ fontWeight: 500,
2299
+ color: "#374151",
2300
+ fontSize: "14px"
2301
+ }, children: "Full name" }),
2302
+ /* @__PURE__ */ jsxRuntime.jsx(
2303
+ "input",
2304
+ {
2305
+ id: "name",
2306
+ type: "text",
2307
+ value: name,
2308
+ onChange: (e) => setName(e.target.value),
2309
+ required: true,
2310
+ disabled: isLoading,
2311
+ style: {
2312
+ width: "100%",
2313
+ padding: "12px 16px",
2314
+ border: "1px solid #ddd",
2315
+ borderRadius: "8px",
2316
+ fontSize: "16px",
2317
+ boxSizing: "border-box",
2318
+ ...appearance?.elements?.formFieldInput
2319
+ },
2320
+ placeholder: "Enter your full name"
2321
+ }
2322
+ )
2323
+ ] }),
2324
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
2325
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
2326
+ display: "block",
2327
+ marginBottom: "8px",
2328
+ fontWeight: 500,
2329
+ color: "#374151",
2330
+ fontSize: "14px"
2331
+ }, children: "Email" }),
2332
+ /* @__PURE__ */ jsxRuntime.jsx(
2333
+ "input",
2334
+ {
2335
+ id: "email",
2336
+ type: "email",
2337
+ value: email,
2338
+ onChange: (e) => setEmail(e.target.value),
2339
+ required: true,
2340
+ disabled: isLoading,
2341
+ style: {
2342
+ width: "100%",
2343
+ padding: "12px 16px",
2344
+ border: "1px solid #ddd",
2345
+ borderRadius: "8px",
2346
+ fontSize: "16px",
2347
+ boxSizing: "border-box",
2348
+ ...appearance?.elements?.formFieldInput
2349
+ },
2350
+ placeholder: "Enter your email"
2351
+ }
2352
+ )
2353
+ ] }),
2354
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
2355
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
2356
+ display: "block",
2357
+ marginBottom: "8px",
2358
+ fontWeight: 500,
2359
+ color: "#374151",
2360
+ fontSize: "14px"
2361
+ }, children: "Password" }),
2362
+ /* @__PURE__ */ jsxRuntime.jsx(
2363
+ "input",
2364
+ {
2365
+ id: "password",
2366
+ type: showPassword ? "text" : "password",
2367
+ value: password,
2368
+ onChange: (e) => setPassword(e.target.value),
2369
+ required: true,
2370
+ disabled: isLoading,
2371
+ minLength: 6,
2372
+ style: {
2373
+ width: "100%",
2374
+ padding: "12px 16px",
2375
+ border: "1px solid #ddd",
2376
+ borderRadius: "8px",
2377
+ fontSize: "16px",
2378
+ boxSizing: "border-box",
2379
+ ...appearance?.elements?.formFieldInput
2380
+ },
2381
+ placeholder: "Create a password"
2382
+ }
2383
+ ),
2384
+ /* @__PURE__ */ jsxRuntime.jsx(
2385
+ "button",
2386
+ {
2387
+ type: "button",
2388
+ onClick: () => setShowPassword(!showPassword),
2389
+ style: {
2390
+ position: "absolute",
2391
+ right: "12px",
2392
+ top: "38px",
2393
+ background: "none",
2394
+ border: "none",
2395
+ cursor: "pointer",
2396
+ color: "#666",
2397
+ fontSize: "14px"
2398
+ },
2399
+ children: showPassword ? "Hide" : "Show"
2400
+ }
2401
+ ),
2402
+ password && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "8px" }, children: [
2403
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2404
+ height: "4px",
2405
+ backgroundColor: "#eee",
2406
+ borderRadius: "2px",
2407
+ overflow: "hidden"
2408
+ }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2409
+ height: "100%",
2410
+ width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
2411
+ backgroundColor: passwordStrength.color,
2412
+ transition: "all 0.3s ease"
2413
+ } }) }),
2414
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
2415
+ fontSize: "12px",
2416
+ color: passwordStrength.color,
2417
+ marginTop: "4px",
2418
+ textTransform: "capitalize"
2419
+ }, children: [
2420
+ passwordStrength.strength,
2421
+ " password"
2422
+ ] })
2423
+ ] })
2424
+ ] }),
2425
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
2426
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "confirmPassword", style: {
2427
+ display: "block",
2428
+ marginBottom: "8px",
2429
+ fontWeight: 500,
2430
+ color: "#374151",
2431
+ fontSize: "14px"
2432
+ }, children: "Confirm password" }),
2433
+ /* @__PURE__ */ jsxRuntime.jsx(
2434
+ "input",
2435
+ {
2436
+ id: "confirmPassword",
2437
+ type: showPassword ? "text" : "password",
2438
+ value: confirmPassword,
2439
+ onChange: (e) => setConfirmPassword(e.target.value),
2440
+ required: true,
2441
+ disabled: isLoading,
2442
+ style: {
2443
+ width: "100%",
2444
+ padding: "12px 16px",
2445
+ border: "1px solid #ddd",
2446
+ borderRadius: "8px",
2447
+ fontSize: "16px",
2448
+ boxSizing: "border-box",
2449
+ ...appearance?.elements?.formFieldInput
2450
+ },
2451
+ placeholder: "Confirm your password"
2452
+ }
2453
+ )
2454
+ ] }),
2455
+ /* @__PURE__ */ jsxRuntime.jsx(
2456
+ "button",
2457
+ {
2458
+ type: "submit",
2459
+ disabled: isLoading,
2460
+ style: {
2461
+ width: "100%",
2462
+ padding: "14px",
2463
+ backgroundColor: "#007bff",
2464
+ color: "white",
2465
+ border: "none",
2466
+ borderRadius: "8px",
2467
+ fontSize: "16px",
2468
+ fontWeight: 600,
2469
+ cursor: "pointer",
2470
+ transition: "all 0.2s ease",
2471
+ ...appearance?.elements?.formButtonPrimary
2472
+ },
2473
+ children: isLoading ? "Creating account..." : "Sign up"
2474
+ }
2475
+ )
2476
+ ] }) });
2477
+ };
2478
+ var SignOut = ({ redirectUrl }) => {
2479
+ const { signOut } = useAuth2();
2480
+ react.useEffect(() => {
2481
+ const performSignOut = async () => {
2482
+ await signOut();
2483
+ const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
2484
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2485
+ window.location.href = `${baseUrl}${redirect}`;
2486
+ };
2487
+ performSignOut();
2488
+ }, [signOut, redirectUrl]);
2489
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Signing out..." }) });
2490
+ };
2491
+ var UserButton = ({ showName = false, appearance }) => {
2492
+ const { user, signOut } = useAuth2();
2493
+ const [isOpen, setIsOpen] = react.useState(false);
2494
+ const dropdownRef = react.useRef(null);
2495
+ react.useEffect(() => {
2496
+ const handleClickOutside = (event) => {
2497
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
2498
+ setIsOpen(false);
2499
+ }
2500
+ };
2501
+ document.addEventListener("mousedown", handleClickOutside);
2502
+ return () => document.removeEventListener("mousedown", handleClickOutside);
2503
+ }, []);
2504
+ if (!user)
2505
+ return null;
2506
+ const getInitials = (name) => {
2507
+ return name.split(" ").map((n) => n[0]).join("").toUpperCase().slice(0, 2);
2508
+ };
2509
+ const handleSignOut = async () => {
2510
+ await signOut();
2511
+ const redirect = process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
2512
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2513
+ window.location.href = `${baseUrl}${redirect}`;
2514
+ };
2515
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative", ...appearance?.elements?.userButtonBox }, ref: dropdownRef, children: [
2516
+ /* @__PURE__ */ jsxRuntime.jsxs(
2517
+ "button",
2518
+ {
2519
+ onClick: () => setIsOpen(!isOpen),
2520
+ style: {
2521
+ display: "flex",
2522
+ alignItems: "center",
2523
+ gap: "8px",
2524
+ padding: "6px",
2525
+ backgroundColor: "transparent",
2526
+ border: "none",
2527
+ borderRadius: "8px",
2528
+ cursor: "pointer",
2529
+ transition: "background-color 0.2s",
2530
+ ...appearance?.elements?.userButtonTrigger
2531
+ },
2532
+ onMouseEnter: (e) => {
2533
+ e.currentTarget.style.backgroundColor = "#f5f5f5";
2534
+ },
2535
+ onMouseLeave: (e) => {
2536
+ e.currentTarget.style.backgroundColor = "transparent";
2537
+ },
2538
+ children: [
2539
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2540
+ width: "36px",
2541
+ height: "36px",
2542
+ borderRadius: "50%",
2543
+ backgroundColor: "#007bff",
2544
+ color: "white",
2545
+ display: "flex",
2546
+ alignItems: "center",
2547
+ justifyContent: "center",
2548
+ fontSize: "14px",
2549
+ fontWeight: 600
2550
+ }, children: getInitials(user.name) }),
2551
+ showName && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "14px", fontWeight: 500, color: "#333" }, children: user.name })
2552
+ ]
2553
+ }
2554
+ ),
2555
+ isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
2556
+ position: "absolute",
2557
+ top: "100%",
2558
+ right: 0,
2559
+ marginTop: "8px",
2560
+ width: "240px",
2561
+ backgroundColor: "white",
2562
+ borderRadius: "12px",
2563
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.15)",
2564
+ border: "1px solid #eaeaea",
2565
+ zIndex: 1e3,
2566
+ ...appearance?.elements?.userButtonPopoverCard
2567
+ }, children: [
2568
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2569
+ padding: "16px",
2570
+ borderBottom: "1px solid #eee"
2571
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
2572
+ display: "flex",
2573
+ alignItems: "center",
2574
+ gap: "12px"
2575
+ }, children: [
2576
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2577
+ width: "48px",
2578
+ height: "48px",
2579
+ borderRadius: "50%",
2580
+ backgroundColor: "#007bff",
2581
+ color: "white",
2582
+ display: "flex",
2583
+ alignItems: "center",
2584
+ justifyContent: "center",
2585
+ fontSize: "18px",
2586
+ fontWeight: 600
2587
+ }, children: getInitials(user.name) }),
2588
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
2589
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2590
+ fontSize: "14px",
2591
+ fontWeight: 600,
2592
+ color: "#333",
2593
+ overflow: "hidden",
2594
+ textOverflow: "ellipsis",
2595
+ whiteSpace: "nowrap"
2596
+ }, children: user.name }),
2597
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2598
+ fontSize: "12px",
2599
+ color: "#666",
2600
+ overflow: "hidden",
2601
+ textOverflow: "ellipsis",
2602
+ whiteSpace: "nowrap"
2603
+ }, children: user.email })
2604
+ ] })
2605
+ ] }) }),
2606
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "8px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
2607
+ "button",
2608
+ {
2609
+ onClick: handleSignOut,
2610
+ style: {
2611
+ width: "100%",
2612
+ padding: "10px 16px",
2613
+ backgroundColor: "transparent",
2614
+ border: "none",
2615
+ borderRadius: "8px",
2616
+ textAlign: "left",
2617
+ cursor: "pointer",
2618
+ fontSize: "14px",
2619
+ color: "#333",
2620
+ fontWeight: 500,
2621
+ transition: "background-color 0.2s"
2622
+ },
2623
+ onMouseEnter: (e) => {
2624
+ e.currentTarget.style.backgroundColor = "#f5f5f5";
2625
+ },
2626
+ onMouseLeave: (e) => {
2627
+ e.currentTarget.style.backgroundColor = "transparent";
2628
+ },
2629
+ children: "Sign out"
2630
+ }
2631
+ ) })
2632
+ ] })
2633
+ ] });
2634
+ };
2635
+ var ProtectedRoute = ({
2636
+ children,
2637
+ fallback,
2638
+ redirectTo
2639
+ }) => {
2640
+ const { isSignedIn, isLoaded } = useAuth2();
2641
+ react.useEffect(() => {
2642
+ if (isLoaded && !isSignedIn) {
2643
+ const loginPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
2644
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2645
+ window.location.href = `${baseUrl}${loginPath}`;
2646
+ }
2647
+ }, [isSignedIn, isLoaded, redirectTo]);
2648
+ if (!isLoaded) {
2649
+ return fallback || /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2650
+ display: "flex",
2651
+ justifyContent: "center",
2652
+ alignItems: "center",
2653
+ minHeight: "100vh"
2654
+ }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }) });
2655
+ }
2656
+ if (!isSignedIn) {
2657
+ return fallback || null;
2658
+ }
2659
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2660
+ };
2661
+ var PublicRoute = ({
2662
+ children,
2663
+ redirectTo
2664
+ }) => {
2665
+ const { isSignedIn, isLoaded } = useAuth2();
2666
+ react.useEffect(() => {
2667
+ if (isLoaded && isSignedIn) {
2668
+ const dashboardPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
2669
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2670
+ window.location.href = `${baseUrl}${dashboardPath}`;
2671
+ }
2672
+ }, [isSignedIn, isLoaded, redirectTo]);
2673
+ if (!isLoaded) {
2674
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2675
+ display: "flex",
2676
+ justifyContent: "center",
2677
+ alignItems: "center",
2678
+ minHeight: "100vh"
2679
+ }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Loading..." }) });
2680
+ }
2681
+ if (isSignedIn) {
2682
+ return null;
2683
+ }
2684
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2685
+ };
2686
+ var VerifyEmail = ({ token, onSuccess, onError }) => {
2687
+ const { verifyEmailToken } = useAuth2();
2688
+ const [status, setStatus] = react.useState("loading");
2689
+ const [message, setMessage] = react.useState("");
2690
+ react.useEffect(() => {
2691
+ const verify = async () => {
2692
+ const verifyToken = token || (typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("token") : null);
2693
+ if (!verifyToken) {
2694
+ setStatus("error");
2695
+ setMessage("No verification token provided");
2696
+ onError?.("No verification token provided");
2697
+ return;
2698
+ }
2699
+ try {
2700
+ const response = await verifyEmailToken(verifyToken);
2701
+ if (response.success) {
2702
+ setStatus("success");
2703
+ setMessage("Email verified successfully! Redirecting...");
2704
+ onSuccess?.();
2705
+ setTimeout(() => {
2706
+ const redirect = process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_VERIFY || process.env.REACT_APP_AUTH_REDIRECT_AFTER_VERIFY || "/dashboard";
2707
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2708
+ window.location.href = `${baseUrl}${redirect}`;
2709
+ }, 2e3);
2710
+ } else {
2711
+ setStatus("error");
2712
+ setMessage(response.message || "Verification failed");
2713
+ onError?.(response.message || "Verification failed");
2714
+ }
2715
+ } catch (err) {
2716
+ setStatus("error");
2717
+ const errorMsg = err instanceof Error ? err.message : "An error occurred";
2718
+ setMessage(errorMsg);
2719
+ onError?.(errorMsg);
2720
+ }
2721
+ };
2722
+ verify();
2723
+ }, [token, verifyEmailToken, onSuccess, onError]);
2724
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
2725
+ maxWidth: "400px",
2726
+ margin: "40px auto",
2727
+ padding: "30px",
2728
+ borderRadius: "12px",
2729
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
2730
+ backgroundColor: "#ffffff",
2731
+ border: "1px solid #eaeaea",
2732
+ textAlign: "center"
2733
+ }, children: [
2734
+ status === "loading" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2735
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2736
+ width: "48px",
2737
+ height: "48px",
2738
+ margin: "0 auto 20px",
2739
+ border: "4px solid #f3f3f3",
2740
+ borderTop: "4px solid #007bff",
2741
+ borderRadius: "50%",
2742
+ animation: "spin 1s linear infinite"
2743
+ } }),
2744
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: `
2745
+ @keyframes spin {
2746
+ 0% { transform: rotate(0deg); }
2747
+ 100% { transform: rotate(360deg); }
2748
+ }
2749
+ ` }),
2750
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
2751
+ fontSize: "20px",
2752
+ fontWeight: 600,
2753
+ color: "#333",
2754
+ marginBottom: "12px"
2755
+ }, children: "Verifying your email..." }),
2756
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666" }, children: "Please wait while we verify your email address." })
2757
+ ] }),
2758
+ status === "success" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2759
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2760
+ width: "64px",
2761
+ height: "64px",
2762
+ margin: "0 auto 20px",
2763
+ backgroundColor: "#4caf50",
2764
+ borderRadius: "50%",
2765
+ display: "flex",
2766
+ alignItems: "center",
2767
+ justifyContent: "center"
2768
+ }, 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" }) }) }),
2769
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
2770
+ fontSize: "20px",
2771
+ fontWeight: 600,
2772
+ color: "#333",
2773
+ marginBottom: "12px"
2774
+ }, children: "Email Verified!" }),
2775
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666" }, children: message })
2776
+ ] }),
2777
+ status === "error" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2778
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2779
+ width: "64px",
2780
+ height: "64px",
2781
+ margin: "0 auto 20px",
2782
+ backgroundColor: "#f44336",
2783
+ borderRadius: "50%",
2784
+ display: "flex",
2785
+ alignItems: "center",
2786
+ justifyContent: "center"
2787
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "3", children: [
2788
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
2789
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
2790
+ ] }) }),
2791
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
2792
+ fontSize: "20px",
2793
+ fontWeight: 600,
2794
+ color: "#333",
2795
+ marginBottom: "12px"
2796
+ }, children: "Verification Failed" }),
2797
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666", marginBottom: "20px" }, children: message }),
2798
+ /* @__PURE__ */ jsxRuntime.jsx(
2799
+ "button",
2800
+ {
2801
+ onClick: () => {
2802
+ const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
2803
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2804
+ window.location.href = `${baseUrl}${loginPath}`;
2805
+ },
2806
+ style: {
2807
+ padding: "10px 20px",
2808
+ backgroundColor: "#007bff",
2809
+ color: "white",
2810
+ border: "none",
2811
+ borderRadius: "8px",
2812
+ fontSize: "14px",
2813
+ fontWeight: 600,
2814
+ cursor: "pointer"
2815
+ },
2816
+ children: "Go to Login"
2817
+ }
2818
+ )
2819
+ ] })
2820
+ ] });
2821
+ };
2822
+ var ForgotPassword = ({ appearance }) => {
2823
+ const { forgotPassword } = useAuth2();
2824
+ const [email, setEmail] = react.useState("");
2825
+ const [isLoading, setIsLoading] = react.useState(false);
2826
+ const [error, setError] = react.useState(null);
2827
+ const [success, setSuccess] = react.useState(null);
2828
+ const handleSubmit = async (e) => {
2829
+ e.preventDefault();
2830
+ setIsLoading(true);
2831
+ setError(null);
2832
+ setSuccess(null);
2833
+ try {
2834
+ const response = await forgotPassword(email);
2835
+ if (response.success) {
2836
+ setSuccess("Password reset link sent! Please check your email.");
2837
+ setEmail("");
2838
+ } else {
2839
+ setError(response.message || "Failed to send reset link");
2840
+ }
2841
+ } catch (err) {
2842
+ setError(err instanceof Error ? err.message : "An error occurred");
2843
+ } finally {
2844
+ setIsLoading(false);
2845
+ }
2846
+ };
2847
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2848
+ maxWidth: "400px",
2849
+ margin: "0 auto",
2850
+ padding: "30px",
2851
+ borderRadius: "12px",
2852
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
2853
+ backgroundColor: "#ffffff",
2854
+ border: "1px solid #eaeaea",
2855
+ ...appearance?.elements?.card
2856
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
2857
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
2858
+ textAlign: "center",
2859
+ marginBottom: "12px",
2860
+ color: "#1f2937",
2861
+ fontSize: "24px",
2862
+ fontWeight: 600,
2863
+ ...appearance?.elements?.headerTitle
2864
+ }, children: "Forgot password?" }),
2865
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: {
2866
+ textAlign: "center",
2867
+ marginBottom: "24px",
2868
+ color: "#666",
2869
+ fontSize: "14px"
2870
+ }, children: "Enter your email address and we'll send you a link to reset your password." }),
2871
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2872
+ padding: "12px 16px",
2873
+ marginBottom: "20px",
2874
+ backgroundColor: "#fee",
2875
+ color: "#c33",
2876
+ border: "1px solid #fcc",
2877
+ borderRadius: "8px",
2878
+ fontSize: "14px"
2879
+ }, children: error }),
2880
+ success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
2881
+ padding: "12px 16px",
2882
+ marginBottom: "20px",
2883
+ backgroundColor: "#efe",
2884
+ color: "#3c3",
2885
+ border: "1px solid #cfc",
2886
+ borderRadius: "8px",
2887
+ fontSize: "14px"
2888
+ }, children: success }),
2889
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
2890
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "email", style: {
2891
+ display: "block",
2892
+ marginBottom: "8px",
2893
+ fontWeight: 500,
2894
+ color: "#374151",
2895
+ fontSize: "14px"
2896
+ }, children: "Email" }),
2897
+ /* @__PURE__ */ jsxRuntime.jsx(
2898
+ "input",
2899
+ {
2900
+ id: "email",
2901
+ type: "email",
2902
+ value: email,
2903
+ onChange: (e) => setEmail(e.target.value),
2904
+ required: true,
2905
+ disabled: isLoading,
2906
+ style: {
2907
+ width: "100%",
2908
+ padding: "12px 16px",
2909
+ border: "1px solid #ddd",
2910
+ borderRadius: "8px",
2911
+ fontSize: "16px",
2912
+ boxSizing: "border-box",
2913
+ ...appearance?.elements?.formFieldInput
2914
+ },
2915
+ placeholder: "Enter your email"
2916
+ }
2917
+ )
2918
+ ] }),
2919
+ /* @__PURE__ */ jsxRuntime.jsx(
2920
+ "button",
2921
+ {
2922
+ type: "submit",
2923
+ disabled: isLoading,
2924
+ style: {
2925
+ width: "100%",
2926
+ padding: "14px",
2927
+ backgroundColor: "#007bff",
2928
+ color: "white",
2929
+ border: "none",
2930
+ borderRadius: "8px",
2931
+ fontSize: "16px",
2932
+ fontWeight: 600,
2933
+ cursor: "pointer",
2934
+ transition: "all 0.2s ease",
2935
+ marginBottom: "16px",
2936
+ ...appearance?.elements?.formButtonPrimary
2937
+ },
2938
+ children: isLoading ? "Sending..." : "Send reset link"
2939
+ }
2940
+ ),
2941
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(
2942
+ "button",
2943
+ {
2944
+ type: "button",
2945
+ onClick: () => {
2946
+ const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
2947
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2948
+ window.location.href = `${baseUrl}${loginPath}`;
2949
+ },
2950
+ disabled: isLoading,
2951
+ style: {
2952
+ background: "none",
2953
+ border: "none",
2954
+ color: "#007bff",
2955
+ cursor: "pointer",
2956
+ fontSize: "14px",
2957
+ fontWeight: 600
2958
+ },
2959
+ children: "Back to sign in"
2960
+ }
2961
+ ) })
2962
+ ] }) });
2963
+ };
2964
+ var ResetPassword = ({ token, appearance }) => {
2965
+ const { resetPassword } = useAuth2();
2966
+ const [resetToken, setResetToken] = react.useState(token || "");
2967
+ const [password, setPassword] = react.useState("");
2968
+ const [confirmPassword, setConfirmPassword] = react.useState("");
2969
+ const [showPassword, setShowPassword] = react.useState(false);
2970
+ const [isLoading, setIsLoading] = react.useState(false);
2971
+ const [error, setError] = react.useState(null);
2972
+ const [success, setSuccess] = react.useState(false);
2973
+ react.useEffect(() => {
2974
+ if (!resetToken && typeof window !== "undefined") {
2975
+ const urlToken = new URLSearchParams(window.location.search).get("token");
2976
+ if (urlToken) {
2977
+ setResetToken(urlToken);
2978
+ }
2979
+ }
2980
+ }, [resetToken]);
2981
+ const getPasswordStrength = (pwd) => {
2982
+ if (!pwd)
2983
+ return { strength: "weak", color: "#ddd" };
2984
+ let score = 0;
2985
+ if (pwd.length >= 6)
2986
+ score++;
2987
+ if (pwd.length >= 8)
2988
+ score++;
2989
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
2990
+ score++;
2991
+ if (/\d/.test(pwd))
2992
+ score++;
2993
+ if (/[^a-zA-Z\d]/.test(pwd))
2994
+ score++;
2995
+ if (score <= 2)
2996
+ return { strength: "weak", color: "#f44" };
2997
+ if (score <= 3)
2998
+ return { strength: "medium", color: "#fa4" };
2999
+ return { strength: "strong", color: "#4f4" };
3000
+ };
3001
+ const passwordStrength = getPasswordStrength(password);
3002
+ const handleSubmit = async (e) => {
3003
+ e.preventDefault();
3004
+ setIsLoading(true);
3005
+ setError(null);
3006
+ if (password !== confirmPassword) {
3007
+ setError("Passwords do not match");
3008
+ setIsLoading(false);
3009
+ return;
3010
+ }
3011
+ if (password.length < 6) {
3012
+ setError("Password must be at least 6 characters");
3013
+ setIsLoading(false);
3014
+ return;
3015
+ }
3016
+ if (!resetToken) {
3017
+ setError("Invalid reset token");
3018
+ setIsLoading(false);
3019
+ return;
3020
+ }
3021
+ try {
3022
+ const response = await resetPassword(resetToken, password);
3023
+ if (response.success) {
3024
+ setSuccess(true);
3025
+ setTimeout(() => {
3026
+ const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
3027
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
3028
+ window.location.href = `${baseUrl}${loginPath}`;
3029
+ }, 2e3);
3030
+ } else {
3031
+ setError(response.message || "Failed to reset password");
3032
+ }
3033
+ } catch (err) {
3034
+ setError(err instanceof Error ? err.message : "An error occurred");
3035
+ } finally {
3036
+ setIsLoading(false);
3037
+ }
3038
+ };
3039
+ if (success) {
3040
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
3041
+ maxWidth: "400px",
3042
+ margin: "40px auto",
3043
+ padding: "30px",
3044
+ borderRadius: "12px",
3045
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
3046
+ backgroundColor: "#ffffff",
3047
+ border: "1px solid #eaeaea",
3048
+ textAlign: "center"
3049
+ }, children: [
3050
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3051
+ width: "64px",
3052
+ height: "64px",
3053
+ margin: "0 auto 20px",
3054
+ backgroundColor: "#4caf50",
3055
+ borderRadius: "50%",
3056
+ display: "flex",
3057
+ alignItems: "center",
3058
+ justifyContent: "center"
3059
+ }, 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" }) }) }),
3060
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
3061
+ fontSize: "20px",
3062
+ fontWeight: 600,
3063
+ color: "#333",
3064
+ marginBottom: "12px"
3065
+ }, children: "Password Reset Successful!" }),
3066
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#666" }, children: "Your password has been reset. Redirecting to login..." })
3067
+ ] });
3068
+ }
3069
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3070
+ maxWidth: "400px",
3071
+ margin: "0 auto",
3072
+ padding: "30px",
3073
+ borderRadius: "12px",
3074
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
3075
+ backgroundColor: "#ffffff",
3076
+ border: "1px solid #eaeaea",
3077
+ ...appearance?.elements?.card
3078
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
3079
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
3080
+ textAlign: "center",
3081
+ marginBottom: "12px",
3082
+ color: "#1f2937",
3083
+ fontSize: "24px",
3084
+ fontWeight: 600,
3085
+ ...appearance?.elements?.headerTitle
3086
+ }, children: "Reset your password" }),
3087
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: {
3088
+ textAlign: "center",
3089
+ marginBottom: "24px",
3090
+ color: "#666",
3091
+ fontSize: "14px"
3092
+ }, children: "Enter your new password below." }),
3093
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3094
+ padding: "12px 16px",
3095
+ marginBottom: "20px",
3096
+ backgroundColor: "#fee",
3097
+ color: "#c33",
3098
+ border: "1px solid #fcc",
3099
+ borderRadius: "8px",
3100
+ fontSize: "14px"
3101
+ }, children: error }),
3102
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
3103
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "password", style: {
3104
+ display: "block",
3105
+ marginBottom: "8px",
3106
+ fontWeight: 500,
3107
+ color: "#374151",
3108
+ fontSize: "14px"
3109
+ }, children: "New password" }),
3110
+ /* @__PURE__ */ jsxRuntime.jsx(
3111
+ "input",
3112
+ {
3113
+ id: "password",
3114
+ type: showPassword ? "text" : "password",
3115
+ value: password,
3116
+ onChange: (e) => setPassword(e.target.value),
3117
+ required: true,
3118
+ disabled: isLoading,
3119
+ minLength: 6,
3120
+ style: {
3121
+ width: "100%",
3122
+ padding: "12px 16px",
3123
+ border: "1px solid #ddd",
3124
+ borderRadius: "8px",
3125
+ fontSize: "16px",
3126
+ boxSizing: "border-box",
3127
+ ...appearance?.elements?.formFieldInput
3128
+ },
3129
+ placeholder: "Enter new password"
3130
+ }
3131
+ ),
3132
+ /* @__PURE__ */ jsxRuntime.jsx(
3133
+ "button",
3134
+ {
3135
+ type: "button",
3136
+ onClick: () => setShowPassword(!showPassword),
3137
+ style: {
3138
+ position: "absolute",
3139
+ right: "12px",
3140
+ top: "38px",
3141
+ background: "none",
3142
+ border: "none",
3143
+ cursor: "pointer",
3144
+ color: "#666",
3145
+ fontSize: "14px"
3146
+ },
3147
+ children: showPassword ? "Hide" : "Show"
3148
+ }
3149
+ ),
3150
+ password && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "8px" }, children: [
3151
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3152
+ height: "4px",
3153
+ backgroundColor: "#eee",
3154
+ borderRadius: "2px",
3155
+ overflow: "hidden"
3156
+ }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3157
+ height: "100%",
3158
+ width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
3159
+ backgroundColor: passwordStrength.color,
3160
+ transition: "all 0.3s ease"
3161
+ } }) }),
3162
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
3163
+ fontSize: "12px",
3164
+ color: passwordStrength.color,
3165
+ marginTop: "4px",
3166
+ textTransform: "capitalize"
3167
+ }, children: [
3168
+ passwordStrength.strength,
3169
+ " password"
3170
+ ] })
3171
+ ] })
3172
+ ] }),
3173
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
3174
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "confirmPassword", style: {
3175
+ display: "block",
3176
+ marginBottom: "8px",
3177
+ fontWeight: 500,
3178
+ color: "#374151",
3179
+ fontSize: "14px"
3180
+ }, children: "Confirm password" }),
3181
+ /* @__PURE__ */ jsxRuntime.jsx(
3182
+ "input",
3183
+ {
3184
+ id: "confirmPassword",
3185
+ type: showPassword ? "text" : "password",
3186
+ value: confirmPassword,
3187
+ onChange: (e) => setConfirmPassword(e.target.value),
3188
+ required: true,
3189
+ disabled: isLoading,
3190
+ style: {
3191
+ width: "100%",
3192
+ padding: "12px 16px",
3193
+ border: "1px solid #ddd",
3194
+ borderRadius: "8px",
3195
+ fontSize: "16px",
3196
+ boxSizing: "border-box",
3197
+ ...appearance?.elements?.formFieldInput
3198
+ },
3199
+ placeholder: "Confirm new password"
3200
+ }
3201
+ )
3202
+ ] }),
3203
+ /* @__PURE__ */ jsxRuntime.jsx(
3204
+ "button",
3205
+ {
3206
+ type: "submit",
3207
+ disabled: isLoading,
3208
+ style: {
3209
+ width: "100%",
3210
+ padding: "14px",
3211
+ backgroundColor: "#007bff",
3212
+ color: "white",
3213
+ border: "none",
3214
+ borderRadius: "8px",
3215
+ fontSize: "16px",
3216
+ fontWeight: 600,
3217
+ cursor: "pointer",
3218
+ transition: "all 0.2s ease",
3219
+ ...appearance?.elements?.formButtonPrimary
3220
+ },
3221
+ children: isLoading ? "Resetting..." : "Reset password"
3222
+ }
3223
+ )
3224
+ ] }) });
3225
+ };
3226
+ var ChangePassword = ({ onSuccess, appearance }) => {
3227
+ const { changePassword } = useAuth2();
3228
+ const [oldPassword, setOldPassword] = react.useState("");
3229
+ const [newPassword, setNewPassword] = react.useState("");
3230
+ const [confirmPassword, setConfirmPassword] = react.useState("");
3231
+ const [showPasswords, setShowPasswords] = react.useState(false);
3232
+ const [isLoading, setIsLoading] = react.useState(false);
3233
+ const [error, setError] = react.useState(null);
3234
+ const [success, setSuccess] = react.useState(false);
3235
+ const getPasswordStrength = (pwd) => {
3236
+ if (!pwd)
3237
+ return { strength: "weak", color: "#ddd" };
3238
+ let score = 0;
3239
+ if (pwd.length >= 6)
3240
+ score++;
3241
+ if (pwd.length >= 8)
3242
+ score++;
3243
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
3244
+ score++;
3245
+ if (/\d/.test(pwd))
3246
+ score++;
3247
+ if (/[^a-zA-Z\d]/.test(pwd))
3248
+ score++;
3249
+ if (score <= 2)
3250
+ return { strength: "weak", color: "#f44" };
3251
+ if (score <= 3)
3252
+ return { strength: "medium", color: "#fa4" };
3253
+ return { strength: "strong", color: "#4f4" };
3254
+ };
3255
+ const passwordStrength = getPasswordStrength(newPassword);
3256
+ const handleSubmit = async (e) => {
3257
+ e.preventDefault();
3258
+ setIsLoading(true);
3259
+ setError(null);
3260
+ setSuccess(false);
3261
+ if (newPassword !== confirmPassword) {
3262
+ setError("New passwords do not match");
3263
+ setIsLoading(false);
3264
+ return;
3265
+ }
3266
+ if (newPassword.length < 6) {
3267
+ setError("New password must be at least 6 characters");
3268
+ setIsLoading(false);
3269
+ return;
3270
+ }
3271
+ try {
3272
+ const response = await changePassword(oldPassword, newPassword);
3273
+ if (response.success) {
3274
+ setSuccess(true);
3275
+ setOldPassword("");
3276
+ setNewPassword("");
3277
+ setConfirmPassword("");
3278
+ onSuccess?.();
3279
+ } else {
3280
+ setError(response.message || "Failed to change password");
3281
+ }
3282
+ } catch (err) {
3283
+ setError(err instanceof Error ? err.message : "An error occurred");
3284
+ } finally {
3285
+ setIsLoading(false);
3286
+ }
3287
+ };
3288
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3289
+ maxWidth: "400px",
3290
+ margin: "0 auto",
3291
+ padding: "30px",
3292
+ borderRadius: "12px",
3293
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
3294
+ backgroundColor: "#ffffff",
3295
+ border: "1px solid #eaeaea",
3296
+ ...appearance?.elements?.card
3297
+ }, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
3298
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: {
3299
+ textAlign: "center",
3300
+ marginBottom: "24px",
3301
+ color: "#1f2937",
3302
+ fontSize: "24px",
3303
+ fontWeight: 600,
3304
+ ...appearance?.elements?.headerTitle
3305
+ }, children: "Change Password" }),
3306
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3307
+ padding: "12px 16px",
3308
+ marginBottom: "20px",
3309
+ backgroundColor: "#fee",
3310
+ color: "#c33",
3311
+ border: "1px solid #fcc",
3312
+ borderRadius: "8px",
3313
+ fontSize: "14px"
3314
+ }, children: error }),
3315
+ success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3316
+ padding: "12px 16px",
3317
+ marginBottom: "20px",
3318
+ backgroundColor: "#efe",
3319
+ color: "#3c3",
3320
+ border: "1px solid #cfc",
3321
+ borderRadius: "8px",
3322
+ fontSize: "14px"
3323
+ }, children: "Password changed successfully!" }),
3324
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
3325
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "oldPassword", style: {
3326
+ display: "block",
3327
+ marginBottom: "8px",
3328
+ fontWeight: 500,
3329
+ color: "#374151",
3330
+ fontSize: "14px"
3331
+ }, children: "Current password" }),
3332
+ /* @__PURE__ */ jsxRuntime.jsx(
3333
+ "input",
3334
+ {
3335
+ id: "oldPassword",
3336
+ type: showPasswords ? "text" : "password",
3337
+ value: oldPassword,
3338
+ onChange: (e) => setOldPassword(e.target.value),
3339
+ required: true,
3340
+ disabled: isLoading,
3341
+ style: {
3342
+ width: "100%",
3343
+ padding: "12px 16px",
3344
+ border: "1px solid #ddd",
3345
+ borderRadius: "8px",
3346
+ fontSize: "16px",
3347
+ boxSizing: "border-box",
3348
+ ...appearance?.elements?.formFieldInput
3349
+ },
3350
+ placeholder: "Enter current password"
3351
+ }
3352
+ )
3353
+ ] }),
3354
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
3355
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "newPassword", style: {
3356
+ display: "block",
3357
+ marginBottom: "8px",
3358
+ fontWeight: 500,
3359
+ color: "#374151",
3360
+ fontSize: "14px"
3361
+ }, children: "New password" }),
3362
+ /* @__PURE__ */ jsxRuntime.jsx(
3363
+ "input",
3364
+ {
3365
+ id: "newPassword",
3366
+ type: showPasswords ? "text" : "password",
3367
+ value: newPassword,
3368
+ onChange: (e) => setNewPassword(e.target.value),
3369
+ required: true,
3370
+ disabled: isLoading,
3371
+ minLength: 6,
3372
+ style: {
3373
+ width: "100%",
3374
+ padding: "12px 16px",
3375
+ border: "1px solid #ddd",
3376
+ borderRadius: "8px",
3377
+ fontSize: "16px",
3378
+ boxSizing: "border-box",
3379
+ ...appearance?.elements?.formFieldInput
3380
+ },
3381
+ placeholder: "Enter new password"
3382
+ }
3383
+ ),
3384
+ newPassword && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginTop: "8px" }, children: [
3385
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3386
+ height: "4px",
3387
+ backgroundColor: "#eee",
3388
+ borderRadius: "2px",
3389
+ overflow: "hidden"
3390
+ }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3391
+ height: "100%",
3392
+ width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
3393
+ backgroundColor: passwordStrength.color,
3394
+ transition: "all 0.3s ease"
3395
+ } }) }),
3396
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
3397
+ fontSize: "12px",
3398
+ color: passwordStrength.color,
3399
+ marginTop: "4px",
3400
+ textTransform: "capitalize"
3401
+ }, children: [
3402
+ passwordStrength.strength,
3403
+ " password"
3404
+ ] })
3405
+ ] })
3406
+ ] }),
3407
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "20px" }, children: [
3408
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "confirmPassword", style: {
3409
+ display: "block",
3410
+ marginBottom: "8px",
3411
+ fontWeight: 500,
3412
+ color: "#374151",
3413
+ fontSize: "14px"
3414
+ }, children: "Confirm new password" }),
3415
+ /* @__PURE__ */ jsxRuntime.jsx(
3416
+ "input",
3417
+ {
3418
+ id: "confirmPassword",
3419
+ type: showPasswords ? "text" : "password",
3420
+ value: confirmPassword,
3421
+ onChange: (e) => setConfirmPassword(e.target.value),
3422
+ required: true,
3423
+ disabled: isLoading,
3424
+ style: {
3425
+ width: "100%",
3426
+ padding: "12px 16px",
3427
+ border: "1px solid #ddd",
3428
+ borderRadius: "8px",
3429
+ fontSize: "16px",
3430
+ boxSizing: "border-box",
3431
+ ...appearance?.elements?.formFieldInput
3432
+ },
3433
+ placeholder: "Confirm new password"
3434
+ }
3435
+ )
3436
+ ] }),
3437
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: "20px" }, children: /* @__PURE__ */ jsxRuntime.jsxs("label", { style: { display: "flex", alignItems: "center", cursor: "pointer" }, children: [
3438
+ /* @__PURE__ */ jsxRuntime.jsx(
3439
+ "input",
3440
+ {
3441
+ type: "checkbox",
3442
+ checked: showPasswords,
3443
+ onChange: (e) => setShowPasswords(e.target.checked),
3444
+ style: { marginRight: "8px" }
3445
+ }
3446
+ ),
3447
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "14px", color: "#666" }, children: "Show passwords" })
3448
+ ] }) }),
3449
+ /* @__PURE__ */ jsxRuntime.jsx(
3450
+ "button",
3451
+ {
3452
+ type: "submit",
3453
+ disabled: isLoading,
3454
+ style: {
3455
+ width: "100%",
3456
+ padding: "14px",
3457
+ backgroundColor: "#007bff",
3458
+ color: "white",
3459
+ border: "none",
3460
+ borderRadius: "8px",
3461
+ fontSize: "16px",
3462
+ fontWeight: 600,
3463
+ cursor: "pointer",
3464
+ transition: "all 0.2s ease",
3465
+ ...appearance?.elements?.formButtonPrimary
3466
+ },
3467
+ children: isLoading ? "Changing password..." : "Change password"
3468
+ }
3469
+ )
3470
+ ] }) });
3471
+ };
3472
+ var UserProfile = ({
3473
+ showAvatar = true,
3474
+ showEmailChange = true,
3475
+ showPasswordChange = true
3476
+ }) => {
3477
+ const { user, updateProfile, updateAvatar, requestEmailChange } = useAuth2();
3478
+ const [name, setName] = react.useState(user?.name || "");
3479
+ const [avatar, setAvatar] = react.useState("");
3480
+ const [newEmail, setNewEmail] = react.useState("");
3481
+ const [isLoading, setIsLoading] = react.useState(false);
3482
+ const [error, setError] = react.useState(null);
3483
+ const [success, setSuccess] = react.useState(null);
3484
+ const handleUpdateName = async (e) => {
3485
+ e.preventDefault();
3486
+ setIsLoading(true);
3487
+ setError(null);
3488
+ setSuccess(null);
3489
+ try {
3490
+ const response = await updateProfile({ name });
3491
+ if (response.success) {
3492
+ setSuccess("Name updated successfully!");
3493
+ } else {
3494
+ setError(response.message || "Failed to update name");
3495
+ }
3496
+ } catch (err) {
3497
+ setError(err instanceof Error ? err.message : "An error occurred");
3498
+ } finally {
3499
+ setIsLoading(false);
3500
+ }
3501
+ };
3502
+ const handleUpdateAvatar = async (e) => {
3503
+ e.preventDefault();
3504
+ setIsLoading(true);
3505
+ setError(null);
3506
+ setSuccess(null);
3507
+ try {
3508
+ const response = await updateAvatar(avatar);
3509
+ if (response.success) {
3510
+ setSuccess("Avatar updated successfully!");
3511
+ setAvatar("");
3512
+ } else {
3513
+ setError(response.message || "Failed to update avatar");
3514
+ }
3515
+ } catch (err) {
3516
+ setError(err instanceof Error ? err.message : "An error occurred");
3517
+ } finally {
3518
+ setIsLoading(false);
3519
+ }
3520
+ };
3521
+ const handleRequestEmailChange = async (e) => {
3522
+ e.preventDefault();
3523
+ setIsLoading(true);
3524
+ setError(null);
3525
+ setSuccess(null);
3526
+ try {
3527
+ const response = await requestEmailChange(newEmail);
3528
+ if (response.success) {
3529
+ setSuccess("Verification email sent! Please check your inbox.");
3530
+ setNewEmail("");
3531
+ } else {
3532
+ setError(response.message || "Failed to request email change");
3533
+ }
3534
+ } catch (err) {
3535
+ setError(err instanceof Error ? err.message : "An error occurred");
3536
+ } finally {
3537
+ setIsLoading(false);
3538
+ }
3539
+ };
3540
+ if (!user)
3541
+ return null;
3542
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { maxWidth: "600px", margin: "0 auto", padding: "20px" }, children: [
3543
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: { marginBottom: "24px", fontSize: "24px", fontWeight: 600 }, children: "Profile Settings" }),
3544
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3545
+ padding: "12px 16px",
3546
+ marginBottom: "20px",
3547
+ backgroundColor: "#fee",
3548
+ color: "#c33",
3549
+ border: "1px solid #fcc",
3550
+ borderRadius: "8px",
3551
+ fontSize: "14px"
3552
+ }, children: error }),
3553
+ success && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3554
+ padding: "12px 16px",
3555
+ marginBottom: "20px",
3556
+ backgroundColor: "#efe",
3557
+ color: "#3c3",
3558
+ border: "1px solid #cfc",
3559
+ borderRadius: "8px",
3560
+ fontSize: "14px"
3561
+ }, children: success }),
3562
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
3563
+ padding: "20px",
3564
+ backgroundColor: "#fff",
3565
+ borderRadius: "8px",
3566
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3567
+ marginBottom: "20px"
3568
+ }, children: [
3569
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Update Name" }),
3570
+ /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleUpdateName, children: [
3571
+ /* @__PURE__ */ jsxRuntime.jsx(
3572
+ "input",
3573
+ {
3574
+ type: "text",
3575
+ value: name,
3576
+ onChange: (e) => setName(e.target.value),
3577
+ required: true,
3578
+ disabled: isLoading,
3579
+ style: {
3580
+ width: "100%",
3581
+ padding: "12px 16px",
3582
+ border: "1px solid #ddd",
3583
+ borderRadius: "8px",
3584
+ fontSize: "16px",
3585
+ boxSizing: "border-box",
3586
+ marginBottom: "12px"
3587
+ },
3588
+ placeholder: "Your name"
3589
+ }
3590
+ ),
3591
+ /* @__PURE__ */ jsxRuntime.jsx(
3592
+ "button",
3593
+ {
3594
+ type: "submit",
3595
+ disabled: isLoading,
3596
+ style: {
3597
+ padding: "10px 20px",
3598
+ backgroundColor: "#007bff",
3599
+ color: "white",
3600
+ border: "none",
3601
+ borderRadius: "8px",
3602
+ fontSize: "14px",
3603
+ fontWeight: 600,
3604
+ cursor: "pointer"
3605
+ },
3606
+ children: "Update Name"
3607
+ }
3608
+ )
3609
+ ] })
3610
+ ] }),
3611
+ showAvatar && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
3612
+ padding: "20px",
3613
+ backgroundColor: "#fff",
3614
+ borderRadius: "8px",
3615
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3616
+ marginBottom: "20px"
3617
+ }, children: [
3618
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Update Avatar" }),
3619
+ /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleUpdateAvatar, children: [
3620
+ /* @__PURE__ */ jsxRuntime.jsx(
3621
+ "input",
3622
+ {
3623
+ type: "url",
3624
+ value: avatar,
3625
+ onChange: (e) => setAvatar(e.target.value),
3626
+ required: true,
3627
+ disabled: isLoading,
3628
+ style: {
3629
+ width: "100%",
3630
+ padding: "12px 16px",
3631
+ border: "1px solid #ddd",
3632
+ borderRadius: "8px",
3633
+ fontSize: "16px",
3634
+ boxSizing: "border-box",
3635
+ marginBottom: "12px"
3636
+ },
3637
+ placeholder: "Avatar URL"
3638
+ }
3639
+ ),
3640
+ /* @__PURE__ */ jsxRuntime.jsx(
3641
+ "button",
3642
+ {
3643
+ type: "submit",
3644
+ disabled: isLoading,
3645
+ style: {
3646
+ padding: "10px 20px",
3647
+ backgroundColor: "#007bff",
3648
+ color: "white",
3649
+ border: "none",
3650
+ borderRadius: "8px",
3651
+ fontSize: "14px",
3652
+ fontWeight: 600,
3653
+ cursor: "pointer"
3654
+ },
3655
+ children: "Update Avatar"
3656
+ }
3657
+ )
3658
+ ] })
3659
+ ] }),
3660
+ showEmailChange && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
3661
+ padding: "20px",
3662
+ backgroundColor: "#fff",
3663
+ borderRadius: "8px",
3664
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3665
+ marginBottom: "20px"
3666
+ }, children: [
3667
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Change Email" }),
3668
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: { fontSize: "14px", color: "#666", marginBottom: "12px" }, children: [
3669
+ "Current email: ",
3670
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: user.email })
3671
+ ] }),
3672
+ /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleRequestEmailChange, children: [
3673
+ /* @__PURE__ */ jsxRuntime.jsx(
3674
+ "input",
3675
+ {
3676
+ type: "email",
3677
+ value: newEmail,
3678
+ onChange: (e) => setNewEmail(e.target.value),
3679
+ required: true,
3680
+ disabled: isLoading,
3681
+ style: {
3682
+ width: "100%",
3683
+ padding: "12px 16px",
3684
+ border: "1px solid #ddd",
3685
+ borderRadius: "8px",
3686
+ fontSize: "16px",
3687
+ boxSizing: "border-box",
3688
+ marginBottom: "12px"
3689
+ },
3690
+ placeholder: "New email address"
3691
+ }
3692
+ ),
3693
+ /* @__PURE__ */ jsxRuntime.jsx(
3694
+ "button",
3695
+ {
3696
+ type: "submit",
3697
+ disabled: isLoading,
3698
+ style: {
3699
+ padding: "10px 20px",
3700
+ backgroundColor: "#007bff",
3701
+ color: "white",
3702
+ border: "none",
3703
+ borderRadius: "8px",
3704
+ fontSize: "14px",
3705
+ fontWeight: 600,
3706
+ cursor: "pointer"
3707
+ },
3708
+ children: "Request Email Change"
3709
+ }
3710
+ )
3711
+ ] })
3712
+ ] })
3713
+ ] });
3714
+ };
1750
3715
 
1751
3716
  exports.AuthFlow = AuthFlow;
3717
+ exports.ChangePassword = ChangePassword;
1752
3718
  exports.EmailVerificationPage = EmailVerificationPage;
3719
+ exports.ForgotPassword = ForgotPassword;
1753
3720
  exports.LoginForm = LoginForm;
1754
3721
  exports.OtpForm = OtpForm;
3722
+ exports.ProtectedRoute = ProtectedRoute;
3723
+ exports.PublicRoute = PublicRoute;
1755
3724
  exports.RegisterForm = RegisterForm;
3725
+ exports.ResetPassword = ResetPassword;
3726
+ exports.SignIn = SignIn;
3727
+ exports.SignOut = SignOut;
3728
+ exports.SignUp = SignUp;
3729
+ exports.UserButton = UserButton;
3730
+ exports.UserProfile = UserProfile;
3731
+ exports.VerifyEmail = VerifyEmail;
1756
3732
  //# sourceMappingURL=out.js.map
1757
3733
  //# sourceMappingURL=index.components.js.map