MCPcopy
hub / github.com/graphile/starter / Settings_Security

Function Settings_Security

@app/client/src/pages/settings/security.tsx:28–230  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26import React, { useCallback, useState } from "react";
27
28const Settings_Security: NextPage = () => {
29 const [error, setError] = useState<Error | ApolloError | null>(null);
30 const [passwordStrength, setPasswordStrength] = useState<number>(0);
31 const [passwordSuggestions, setPasswordSuggestions] = useState<string[]>([]);
32
33 const query = useSharedQuery();
34
35 const [form] = useForm();
36 const [changePassword] = useChangePasswordMutation();
37 const [success, setSuccess] = useState(false);
38
39 const handleSubmit = useCallback(
40 async (values: Store) => {
41 setSuccess(false);
42 setError(null);
43 try {
44 await changePassword({
45 variables: {
46 oldPassword: values.oldPassword,
47 newPassword: values.newPassword,
48 },
49 });
50 setError(null);
51 setSuccess(true);
52 } catch (e) {
53 const errcode = getCodeFromError(e);
54 if (errcode === "WEAKP") {
55 form.setFields([
56 {
57 name: "newPassword",
58 value: form.getFieldValue("newPassword"),
59 errors: [
60 "The server believes this passphrase is too weak, please make it stronger",
61 ],
62 },
63 ]);
64 } else if (errcode === "CREDS") {
65 form.setFields([
66 {
67 name: "oldPassword",
68 value: form.getFieldValue("oldPassword"),
69 errors: ["Incorrect old passphrase"],
70 },
71 ]);
72 } else {
73 setError(e);
74 }
75 }
76 },
77 [changePassword, form, setError]
78 );
79
80 const {
81 data,
82 error: graphqlQueryError,
83 loading,
84 } = useSettingsPasswordQuery();
85 const [forgotPassword] = useForgotPasswordMutation();

Callers

nothing calls this directly

Calls 5

getCodeFromErrorFunction · 0.90
setPasswordInfoFunction · 0.90
changePasswordFunction · 0.85
forgotPasswordFunction · 0.85
innerFunction · 0.85

Tested by

no test coverage detected