@githat/nextjs 0.4.0 → 0.4.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.d.mts +73 -1
- package/dist/index.d.ts +73 -1
- package/dist/index.js +475 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +471 -1
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +50 -1
- package/dist/server.d.ts +50 -1
- package/dist/server.js +19 -2
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +17 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -323,13 +323,90 @@ function useGitHat() {
|
|
|
323
323
|
},
|
|
324
324
|
[client, ctx.org?.id]
|
|
325
325
|
);
|
|
326
|
+
const forgotPassword = useCallback2(
|
|
327
|
+
async (email) => {
|
|
328
|
+
const response = await fetch(`${ctx.config.apiUrl}/auth/forgot-password`, {
|
|
329
|
+
method: "POST",
|
|
330
|
+
headers: { "Content-Type": "application/json" },
|
|
331
|
+
body: JSON.stringify({ email })
|
|
332
|
+
});
|
|
333
|
+
if (!response.ok) {
|
|
334
|
+
const error = await response.json().catch(() => ({}));
|
|
335
|
+
throw new Error(error.message || "Failed to send reset email");
|
|
336
|
+
}
|
|
337
|
+
return { success: true };
|
|
338
|
+
},
|
|
339
|
+
[ctx.config.apiUrl]
|
|
340
|
+
);
|
|
341
|
+
const resetPassword = useCallback2(
|
|
342
|
+
async (token, newPassword) => {
|
|
343
|
+
const response = await fetch(`${ctx.config.apiUrl}/auth/reset-password`, {
|
|
344
|
+
method: "POST",
|
|
345
|
+
headers: { "Content-Type": "application/json" },
|
|
346
|
+
body: JSON.stringify({ token, password: newPassword })
|
|
347
|
+
});
|
|
348
|
+
if (!response.ok) {
|
|
349
|
+
const error = await response.json().catch(() => ({}));
|
|
350
|
+
throw new Error(error.message || "Failed to reset password");
|
|
351
|
+
}
|
|
352
|
+
return { success: true };
|
|
353
|
+
},
|
|
354
|
+
[ctx.config.apiUrl]
|
|
355
|
+
);
|
|
356
|
+
const changePassword = useCallback2(
|
|
357
|
+
async (currentPassword, newPassword) => {
|
|
358
|
+
await client.fetchApi("/auth/change-password", {
|
|
359
|
+
method: "POST",
|
|
360
|
+
body: JSON.stringify({ currentPassword, newPassword })
|
|
361
|
+
});
|
|
362
|
+
return { success: true };
|
|
363
|
+
},
|
|
364
|
+
[client]
|
|
365
|
+
);
|
|
366
|
+
const verifyEmail = useCallback2(
|
|
367
|
+
async (token) => {
|
|
368
|
+
const response = await fetch(`${ctx.config.apiUrl}/auth/verify-email`, {
|
|
369
|
+
method: "POST",
|
|
370
|
+
headers: { "Content-Type": "application/json" },
|
|
371
|
+
body: JSON.stringify({ token })
|
|
372
|
+
});
|
|
373
|
+
if (!response.ok) {
|
|
374
|
+
const error = await response.json().catch(() => ({}));
|
|
375
|
+
throw new Error(error.message || "Failed to verify email");
|
|
376
|
+
}
|
|
377
|
+
return { success: true };
|
|
378
|
+
},
|
|
379
|
+
[ctx.config.apiUrl]
|
|
380
|
+
);
|
|
381
|
+
const resendVerificationEmail = useCallback2(
|
|
382
|
+
async (email) => {
|
|
383
|
+
const response = await fetch(`${ctx.config.apiUrl}/auth/resend-verification`, {
|
|
384
|
+
method: "POST",
|
|
385
|
+
headers: { "Content-Type": "application/json" },
|
|
386
|
+
body: JSON.stringify({ email })
|
|
387
|
+
});
|
|
388
|
+
if (!response.ok) {
|
|
389
|
+
const error = await response.json().catch(() => ({}));
|
|
390
|
+
throw new Error(error.message || "Failed to resend verification email");
|
|
391
|
+
}
|
|
392
|
+
return { success: true };
|
|
393
|
+
},
|
|
394
|
+
[ctx.config.apiUrl]
|
|
395
|
+
);
|
|
326
396
|
return {
|
|
327
397
|
fetch: client.fetchApi,
|
|
328
398
|
getUserOrgs: () => client.fetchApi("/user/orgs"),
|
|
329
399
|
verifyMCP: (domain) => client.fetchApi(`/verify/mcp/${domain}`),
|
|
330
400
|
verifyAgent: (wallet) => client.fetchApi(`/verify/agent/${wallet}`),
|
|
331
401
|
getOrgMetadata,
|
|
332
|
-
updateOrgMetadata
|
|
402
|
+
updateOrgMetadata,
|
|
403
|
+
// Password management
|
|
404
|
+
forgotPassword,
|
|
405
|
+
resetPassword,
|
|
406
|
+
changePassword,
|
|
407
|
+
// Email verification
|
|
408
|
+
verifyEmail,
|
|
409
|
+
resendVerificationEmail
|
|
333
410
|
};
|
|
334
411
|
}
|
|
335
412
|
|
|
@@ -772,16 +849,409 @@ function ProtectedRoute({ children, fallback }) {
|
|
|
772
849
|
}
|
|
773
850
|
return /* @__PURE__ */ jsx8(Fragment, { children });
|
|
774
851
|
}
|
|
852
|
+
|
|
853
|
+
// src/components/ForgotPasswordForm.tsx
|
|
854
|
+
import { useState as useState7 } from "react";
|
|
855
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
856
|
+
function ForgotPasswordForm({
|
|
857
|
+
onSuccess,
|
|
858
|
+
onError,
|
|
859
|
+
signInUrl = "/sign-in"
|
|
860
|
+
}) {
|
|
861
|
+
const { forgotPassword } = useGitHat();
|
|
862
|
+
const [email, setEmail] = useState7("");
|
|
863
|
+
const [isLoading, setIsLoading] = useState7(false);
|
|
864
|
+
const [sent, setSent] = useState7(false);
|
|
865
|
+
const [error, setError] = useState7("");
|
|
866
|
+
const emailValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
867
|
+
const handleSubmit = async (e) => {
|
|
868
|
+
e.preventDefault();
|
|
869
|
+
if (!emailValid) {
|
|
870
|
+
setError("Please enter a valid email address");
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
setIsLoading(true);
|
|
874
|
+
setError("");
|
|
875
|
+
try {
|
|
876
|
+
await forgotPassword(email);
|
|
877
|
+
setSent(true);
|
|
878
|
+
onSuccess?.(email);
|
|
879
|
+
} catch (err) {
|
|
880
|
+
const message = err instanceof Error ? err.message : "Failed to send reset email";
|
|
881
|
+
setError(message);
|
|
882
|
+
onError?.(err instanceof Error ? err : new Error(message));
|
|
883
|
+
} finally {
|
|
884
|
+
setIsLoading(false);
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
if (sent) {
|
|
888
|
+
return /* @__PURE__ */ jsxs6("div", { className: "githat-form-container", children: [
|
|
889
|
+
/* @__PURE__ */ jsxs6("div", { className: "githat-form-header", children: [
|
|
890
|
+
/* @__PURE__ */ jsx9("h2", { className: "githat-form-title", children: "Check your email" }),
|
|
891
|
+
/* @__PURE__ */ jsxs6("p", { className: "githat-form-subtitle", children: [
|
|
892
|
+
"We sent a password reset link to ",
|
|
893
|
+
/* @__PURE__ */ jsx9("strong", { children: email })
|
|
894
|
+
] })
|
|
895
|
+
] }),
|
|
896
|
+
/* @__PURE__ */ jsx9("a", { href: signInUrl, className: "githat-link", children: "Back to sign in" }),
|
|
897
|
+
/* @__PURE__ */ jsxs6("p", { className: "githat-powered-by", children: [
|
|
898
|
+
"Secured by ",
|
|
899
|
+
/* @__PURE__ */ jsx9("strong", { children: "GitHat" })
|
|
900
|
+
] })
|
|
901
|
+
] });
|
|
902
|
+
}
|
|
903
|
+
return /* @__PURE__ */ jsxs6("div", { className: "githat-form-container", children: [
|
|
904
|
+
/* @__PURE__ */ jsxs6("div", { className: "githat-form-header", children: [
|
|
905
|
+
/* @__PURE__ */ jsx9("h2", { className: "githat-form-title", children: "Forgot password" }),
|
|
906
|
+
/* @__PURE__ */ jsx9("p", { className: "githat-form-subtitle", children: "Enter your email and we'll send you a reset link" })
|
|
907
|
+
] }),
|
|
908
|
+
error && /* @__PURE__ */ jsx9("div", { className: "githat-alert githat-alert-error", role: "alert", "aria-live": "polite", children: error }),
|
|
909
|
+
/* @__PURE__ */ jsxs6("form", { onSubmit: handleSubmit, className: "githat-form", "aria-label": "Forgot password form", children: [
|
|
910
|
+
/* @__PURE__ */ jsxs6("div", { className: "githat-field", children: [
|
|
911
|
+
/* @__PURE__ */ jsx9("label", { className: "githat-label", htmlFor: "githat-forgot-email", children: "Email" }),
|
|
912
|
+
/* @__PURE__ */ jsx9(
|
|
913
|
+
"input",
|
|
914
|
+
{
|
|
915
|
+
id: "githat-forgot-email",
|
|
916
|
+
className: "githat-input",
|
|
917
|
+
type: "email",
|
|
918
|
+
value: email,
|
|
919
|
+
onChange: (e) => setEmail(e.target.value),
|
|
920
|
+
placeholder: "you@example.com",
|
|
921
|
+
autoComplete: "email",
|
|
922
|
+
disabled: isLoading,
|
|
923
|
+
required: true
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
] }),
|
|
927
|
+
/* @__PURE__ */ jsx9(
|
|
928
|
+
"button",
|
|
929
|
+
{
|
|
930
|
+
type: "submit",
|
|
931
|
+
className: "githat-button githat-button-primary",
|
|
932
|
+
disabled: isLoading || !email || email.length > 0 && !emailValid,
|
|
933
|
+
children: isLoading ? "Sending..." : "Send reset link"
|
|
934
|
+
}
|
|
935
|
+
)
|
|
936
|
+
] }),
|
|
937
|
+
/* @__PURE__ */ jsxs6("p", { className: "githat-form-footer", children: [
|
|
938
|
+
"Remember your password? ",
|
|
939
|
+
/* @__PURE__ */ jsx9("a", { href: signInUrl, className: "githat-link", children: "Sign in" })
|
|
940
|
+
] }),
|
|
941
|
+
/* @__PURE__ */ jsxs6("p", { className: "githat-powered-by", children: [
|
|
942
|
+
"Secured by ",
|
|
943
|
+
/* @__PURE__ */ jsx9("strong", { children: "GitHat" })
|
|
944
|
+
] })
|
|
945
|
+
] });
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/components/ResetPasswordForm.tsx
|
|
949
|
+
import { useState as useState8 } from "react";
|
|
950
|
+
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
951
|
+
function ResetPasswordForm({
|
|
952
|
+
token,
|
|
953
|
+
onSuccess,
|
|
954
|
+
onError,
|
|
955
|
+
signInUrl = "/sign-in",
|
|
956
|
+
minPasswordLength = 8
|
|
957
|
+
}) {
|
|
958
|
+
const { resetPassword } = useGitHat();
|
|
959
|
+
const [password, setPassword] = useState8("");
|
|
960
|
+
const [confirm, setConfirm] = useState8("");
|
|
961
|
+
const [isLoading, setIsLoading] = useState8(false);
|
|
962
|
+
const [success, setSuccess] = useState8(false);
|
|
963
|
+
const [error, setError] = useState8("");
|
|
964
|
+
const handleSubmit = async (e) => {
|
|
965
|
+
e.preventDefault();
|
|
966
|
+
if (password !== confirm) {
|
|
967
|
+
setError("Passwords do not match");
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
if (password.length < minPasswordLength) {
|
|
971
|
+
setError(`Password must be at least ${minPasswordLength} characters`);
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
setIsLoading(true);
|
|
975
|
+
setError("");
|
|
976
|
+
try {
|
|
977
|
+
await resetPassword(token, password);
|
|
978
|
+
setSuccess(true);
|
|
979
|
+
onSuccess?.();
|
|
980
|
+
} catch (err) {
|
|
981
|
+
const message = err instanceof Error ? err.message : "Failed to reset password";
|
|
982
|
+
setError(message);
|
|
983
|
+
onError?.(err instanceof Error ? err : new Error(message));
|
|
984
|
+
} finally {
|
|
985
|
+
setIsLoading(false);
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
if (success) {
|
|
989
|
+
return /* @__PURE__ */ jsxs7("div", { className: "githat-form-container", children: [
|
|
990
|
+
/* @__PURE__ */ jsxs7("div", { className: "githat-form-header", children: [
|
|
991
|
+
/* @__PURE__ */ jsx10("h2", { className: "githat-form-title", children: "Password reset!" }),
|
|
992
|
+
/* @__PURE__ */ jsx10("p", { className: "githat-form-subtitle", children: "Your password has been successfully reset." })
|
|
993
|
+
] }),
|
|
994
|
+
/* @__PURE__ */ jsx10("a", { href: signInUrl, className: "githat-button githat-button-primary", style: { display: "block", textAlign: "center", textDecoration: "none" }, children: "Sign in" }),
|
|
995
|
+
/* @__PURE__ */ jsxs7("p", { className: "githat-powered-by", children: [
|
|
996
|
+
"Secured by ",
|
|
997
|
+
/* @__PURE__ */ jsx10("strong", { children: "GitHat" })
|
|
998
|
+
] })
|
|
999
|
+
] });
|
|
1000
|
+
}
|
|
1001
|
+
return /* @__PURE__ */ jsxs7("div", { className: "githat-form-container", children: [
|
|
1002
|
+
/* @__PURE__ */ jsxs7("div", { className: "githat-form-header", children: [
|
|
1003
|
+
/* @__PURE__ */ jsx10("h2", { className: "githat-form-title", children: "Reset password" }),
|
|
1004
|
+
/* @__PURE__ */ jsx10("p", { className: "githat-form-subtitle", children: "Enter your new password" })
|
|
1005
|
+
] }),
|
|
1006
|
+
error && /* @__PURE__ */ jsx10("div", { className: "githat-alert githat-alert-error", role: "alert", "aria-live": "polite", children: error }),
|
|
1007
|
+
/* @__PURE__ */ jsxs7("form", { onSubmit: handleSubmit, className: "githat-form", "aria-label": "Reset password form", children: [
|
|
1008
|
+
/* @__PURE__ */ jsxs7("div", { className: "githat-field", children: [
|
|
1009
|
+
/* @__PURE__ */ jsx10("label", { className: "githat-label", htmlFor: "githat-reset-password", children: "New password" }),
|
|
1010
|
+
/* @__PURE__ */ jsx10(
|
|
1011
|
+
"input",
|
|
1012
|
+
{
|
|
1013
|
+
id: "githat-reset-password",
|
|
1014
|
+
className: "githat-input",
|
|
1015
|
+
type: "password",
|
|
1016
|
+
value: password,
|
|
1017
|
+
onChange: (e) => setPassword(e.target.value),
|
|
1018
|
+
placeholder: "Enter new password",
|
|
1019
|
+
autoComplete: "new-password",
|
|
1020
|
+
disabled: isLoading,
|
|
1021
|
+
required: true,
|
|
1022
|
+
minLength: minPasswordLength
|
|
1023
|
+
}
|
|
1024
|
+
)
|
|
1025
|
+
] }),
|
|
1026
|
+
/* @__PURE__ */ jsxs7("div", { className: "githat-field", children: [
|
|
1027
|
+
/* @__PURE__ */ jsx10("label", { className: "githat-label", htmlFor: "githat-reset-confirm", children: "Confirm password" }),
|
|
1028
|
+
/* @__PURE__ */ jsx10(
|
|
1029
|
+
"input",
|
|
1030
|
+
{
|
|
1031
|
+
id: "githat-reset-confirm",
|
|
1032
|
+
className: "githat-input",
|
|
1033
|
+
type: "password",
|
|
1034
|
+
value: confirm,
|
|
1035
|
+
onChange: (e) => setConfirm(e.target.value),
|
|
1036
|
+
placeholder: "Confirm new password",
|
|
1037
|
+
autoComplete: "new-password",
|
|
1038
|
+
disabled: isLoading,
|
|
1039
|
+
required: true
|
|
1040
|
+
}
|
|
1041
|
+
)
|
|
1042
|
+
] }),
|
|
1043
|
+
/* @__PURE__ */ jsx10(
|
|
1044
|
+
"button",
|
|
1045
|
+
{
|
|
1046
|
+
type: "submit",
|
|
1047
|
+
className: "githat-button githat-button-primary",
|
|
1048
|
+
disabled: isLoading || !password || !confirm,
|
|
1049
|
+
children: isLoading ? "Resetting..." : "Reset password"
|
|
1050
|
+
}
|
|
1051
|
+
)
|
|
1052
|
+
] }),
|
|
1053
|
+
/* @__PURE__ */ jsxs7("p", { className: "githat-powered-by", children: [
|
|
1054
|
+
"Secured by ",
|
|
1055
|
+
/* @__PURE__ */ jsx10("strong", { children: "GitHat" })
|
|
1056
|
+
] })
|
|
1057
|
+
] });
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// src/components/VerifyEmailStatus.tsx
|
|
1061
|
+
import { useEffect as useEffect5, useState as useState9 } from "react";
|
|
1062
|
+
import { Fragment as Fragment2, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1063
|
+
function VerifyEmailStatus({
|
|
1064
|
+
token,
|
|
1065
|
+
onSuccess,
|
|
1066
|
+
onError,
|
|
1067
|
+
signInUrl = "/sign-in",
|
|
1068
|
+
redirectDelay = 3e3
|
|
1069
|
+
}) {
|
|
1070
|
+
const { verifyEmail } = useGitHat();
|
|
1071
|
+
const [status, setStatus] = useState9("loading");
|
|
1072
|
+
const [error, setError] = useState9("");
|
|
1073
|
+
useEffect5(() => {
|
|
1074
|
+
if (!token) {
|
|
1075
|
+
setStatus("error");
|
|
1076
|
+
setError("Missing verification token");
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
verifyEmail(token).then(() => {
|
|
1080
|
+
setStatus("success");
|
|
1081
|
+
onSuccess?.();
|
|
1082
|
+
if (signInUrl && redirectDelay > 0) {
|
|
1083
|
+
setTimeout(() => {
|
|
1084
|
+
window.location.href = signInUrl;
|
|
1085
|
+
}, redirectDelay);
|
|
1086
|
+
}
|
|
1087
|
+
}).catch((err) => {
|
|
1088
|
+
setStatus("error");
|
|
1089
|
+
const message = err instanceof Error ? err.message : "Verification failed";
|
|
1090
|
+
setError(message);
|
|
1091
|
+
onError?.(err instanceof Error ? err : new Error(message));
|
|
1092
|
+
});
|
|
1093
|
+
}, [token, verifyEmail, onSuccess, onError, signInUrl, redirectDelay]);
|
|
1094
|
+
return /* @__PURE__ */ jsxs8("div", { className: "githat-form-container", children: [
|
|
1095
|
+
status === "loading" && /* @__PURE__ */ jsxs8("div", { className: "githat-form-header", children: [
|
|
1096
|
+
/* @__PURE__ */ jsx11("h2", { className: "githat-form-title", children: "Verifying email..." }),
|
|
1097
|
+
/* @__PURE__ */ jsx11("p", { className: "githat-form-subtitle", children: "Please wait while we verify your email address." })
|
|
1098
|
+
] }),
|
|
1099
|
+
status === "success" && /* @__PURE__ */ jsxs8(Fragment2, { children: [
|
|
1100
|
+
/* @__PURE__ */ jsxs8("div", { className: "githat-form-header", children: [
|
|
1101
|
+
/* @__PURE__ */ jsx11("h2", { className: "githat-form-title", children: "Email verified!" }),
|
|
1102
|
+
/* @__PURE__ */ jsx11("p", { className: "githat-form-subtitle", children: "Your email has been successfully verified. Redirecting to sign in..." })
|
|
1103
|
+
] }),
|
|
1104
|
+
/* @__PURE__ */ jsx11("a", { href: signInUrl, className: "githat-button githat-button-primary", style: { display: "block", textAlign: "center", textDecoration: "none" }, children: "Sign in now" })
|
|
1105
|
+
] }),
|
|
1106
|
+
status === "error" && /* @__PURE__ */ jsxs8(Fragment2, { children: [
|
|
1107
|
+
/* @__PURE__ */ jsxs8("div", { className: "githat-form-header", children: [
|
|
1108
|
+
/* @__PURE__ */ jsx11("h2", { className: "githat-form-title", children: "Verification failed" }),
|
|
1109
|
+
/* @__PURE__ */ jsx11("p", { className: "githat-form-subtitle", children: error })
|
|
1110
|
+
] }),
|
|
1111
|
+
/* @__PURE__ */ jsxs8("p", { className: "githat-form-footer", children: [
|
|
1112
|
+
"The link may have expired. ",
|
|
1113
|
+
/* @__PURE__ */ jsx11("a", { href: "/sign-up", className: "githat-link", children: "Try signing up again" })
|
|
1114
|
+
] })
|
|
1115
|
+
] }),
|
|
1116
|
+
/* @__PURE__ */ jsxs8("p", { className: "githat-powered-by", children: [
|
|
1117
|
+
"Secured by ",
|
|
1118
|
+
/* @__PURE__ */ jsx11("strong", { children: "GitHat" })
|
|
1119
|
+
] })
|
|
1120
|
+
] });
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
// src/components/ChangePasswordForm.tsx
|
|
1124
|
+
import { useState as useState10 } from "react";
|
|
1125
|
+
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1126
|
+
function ChangePasswordForm({
|
|
1127
|
+
onSuccess,
|
|
1128
|
+
onError,
|
|
1129
|
+
minPasswordLength = 8
|
|
1130
|
+
}) {
|
|
1131
|
+
const { changePassword } = useGitHat();
|
|
1132
|
+
const [current, setCurrent] = useState10("");
|
|
1133
|
+
const [newPass, setNewPass] = useState10("");
|
|
1134
|
+
const [confirm, setConfirm] = useState10("");
|
|
1135
|
+
const [isLoading, setIsLoading] = useState10(false);
|
|
1136
|
+
const [error, setError] = useState10("");
|
|
1137
|
+
const [success, setSuccess] = useState10(false);
|
|
1138
|
+
const handleSubmit = async (e) => {
|
|
1139
|
+
e.preventDefault();
|
|
1140
|
+
if (newPass !== confirm) {
|
|
1141
|
+
setError("Passwords do not match");
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
if (newPass.length < minPasswordLength) {
|
|
1145
|
+
setError(`Password must be at least ${minPasswordLength} characters`);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
setIsLoading(true);
|
|
1149
|
+
setError("");
|
|
1150
|
+
try {
|
|
1151
|
+
await changePassword(current, newPass);
|
|
1152
|
+
setSuccess(true);
|
|
1153
|
+
setCurrent("");
|
|
1154
|
+
setNewPass("");
|
|
1155
|
+
setConfirm("");
|
|
1156
|
+
onSuccess?.();
|
|
1157
|
+
} catch (err) {
|
|
1158
|
+
const message = err instanceof Error ? err.message : "Failed to change password";
|
|
1159
|
+
setError(message);
|
|
1160
|
+
onError?.(err instanceof Error ? err : new Error(message));
|
|
1161
|
+
} finally {
|
|
1162
|
+
setIsLoading(false);
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
return /* @__PURE__ */ jsxs9("div", { className: "githat-form-container", children: [
|
|
1166
|
+
/* @__PURE__ */ jsxs9("div", { className: "githat-form-header", children: [
|
|
1167
|
+
/* @__PURE__ */ jsx12("h2", { className: "githat-form-title", children: "Change password" }),
|
|
1168
|
+
/* @__PURE__ */ jsx12("p", { className: "githat-form-subtitle", children: "Update your account password" })
|
|
1169
|
+
] }),
|
|
1170
|
+
success && /* @__PURE__ */ jsx12("div", { className: "githat-alert githat-alert-success", role: "status", "aria-live": "polite", children: "Password changed successfully!" }),
|
|
1171
|
+
error && /* @__PURE__ */ jsx12("div", { className: "githat-alert githat-alert-error", role: "alert", "aria-live": "polite", children: error }),
|
|
1172
|
+
/* @__PURE__ */ jsxs9("form", { onSubmit: handleSubmit, className: "githat-form", "aria-label": "Change password form", children: [
|
|
1173
|
+
/* @__PURE__ */ jsxs9("div", { className: "githat-field", children: [
|
|
1174
|
+
/* @__PURE__ */ jsx12("label", { className: "githat-label", htmlFor: "githat-change-current", children: "Current password" }),
|
|
1175
|
+
/* @__PURE__ */ jsx12(
|
|
1176
|
+
"input",
|
|
1177
|
+
{
|
|
1178
|
+
id: "githat-change-current",
|
|
1179
|
+
className: "githat-input",
|
|
1180
|
+
type: "password",
|
|
1181
|
+
value: current,
|
|
1182
|
+
onChange: (e) => setCurrent(e.target.value),
|
|
1183
|
+
placeholder: "Enter current password",
|
|
1184
|
+
autoComplete: "current-password",
|
|
1185
|
+
disabled: isLoading,
|
|
1186
|
+
required: true
|
|
1187
|
+
}
|
|
1188
|
+
)
|
|
1189
|
+
] }),
|
|
1190
|
+
/* @__PURE__ */ jsxs9("div", { className: "githat-field", children: [
|
|
1191
|
+
/* @__PURE__ */ jsx12("label", { className: "githat-label", htmlFor: "githat-change-new", children: "New password" }),
|
|
1192
|
+
/* @__PURE__ */ jsx12(
|
|
1193
|
+
"input",
|
|
1194
|
+
{
|
|
1195
|
+
id: "githat-change-new",
|
|
1196
|
+
className: "githat-input",
|
|
1197
|
+
type: "password",
|
|
1198
|
+
value: newPass,
|
|
1199
|
+
onChange: (e) => setNewPass(e.target.value),
|
|
1200
|
+
placeholder: "Enter new password",
|
|
1201
|
+
autoComplete: "new-password",
|
|
1202
|
+
disabled: isLoading,
|
|
1203
|
+
required: true,
|
|
1204
|
+
minLength: minPasswordLength
|
|
1205
|
+
}
|
|
1206
|
+
)
|
|
1207
|
+
] }),
|
|
1208
|
+
/* @__PURE__ */ jsxs9("div", { className: "githat-field", children: [
|
|
1209
|
+
/* @__PURE__ */ jsx12("label", { className: "githat-label", htmlFor: "githat-change-confirm", children: "Confirm new password" }),
|
|
1210
|
+
/* @__PURE__ */ jsx12(
|
|
1211
|
+
"input",
|
|
1212
|
+
{
|
|
1213
|
+
id: "githat-change-confirm",
|
|
1214
|
+
className: "githat-input",
|
|
1215
|
+
type: "password",
|
|
1216
|
+
value: confirm,
|
|
1217
|
+
onChange: (e) => setConfirm(e.target.value),
|
|
1218
|
+
placeholder: "Confirm new password",
|
|
1219
|
+
autoComplete: "new-password",
|
|
1220
|
+
disabled: isLoading,
|
|
1221
|
+
required: true
|
|
1222
|
+
}
|
|
1223
|
+
)
|
|
1224
|
+
] }),
|
|
1225
|
+
/* @__PURE__ */ jsx12(
|
|
1226
|
+
"button",
|
|
1227
|
+
{
|
|
1228
|
+
type: "submit",
|
|
1229
|
+
className: "githat-button githat-button-primary",
|
|
1230
|
+
disabled: isLoading || !current || !newPass || !confirm,
|
|
1231
|
+
children: isLoading ? "Changing..." : "Change password"
|
|
1232
|
+
}
|
|
1233
|
+
)
|
|
1234
|
+
] }),
|
|
1235
|
+
/* @__PURE__ */ jsxs9("p", { className: "githat-powered-by", children: [
|
|
1236
|
+
"Secured by ",
|
|
1237
|
+
/* @__PURE__ */ jsx12("strong", { children: "GitHat" })
|
|
1238
|
+
] })
|
|
1239
|
+
] });
|
|
1240
|
+
}
|
|
775
1241
|
export {
|
|
1242
|
+
ChangePasswordForm,
|
|
1243
|
+
ForgotPasswordForm,
|
|
776
1244
|
GitHatProvider,
|
|
777
1245
|
OrgSwitcher,
|
|
778
1246
|
ProtectedRoute,
|
|
1247
|
+
ResetPasswordForm,
|
|
779
1248
|
SignInButton,
|
|
780
1249
|
SignInForm,
|
|
781
1250
|
SignUpButton,
|
|
782
1251
|
SignUpForm,
|
|
783
1252
|
UserButton,
|
|
784
1253
|
VerifiedBadge,
|
|
1254
|
+
VerifyEmailStatus,
|
|
785
1255
|
useAuth,
|
|
786
1256
|
useData,
|
|
787
1257
|
useGitHat
|