MCPcopy Create free account
hub / github.com/code100x/cms / handleSubmit

Function handleSubmit

src/components/Signin.tsx:111–150  ·  view source on GitHub ↗
(e?: React.FormEvent<HTMLButtonElement>)

Source from the content-addressed store, hash-verified

109 };
110
111 const handleSubmit = async (e?: React.FormEvent<HTMLButtonElement>) => {
112 const loadId = toast.loading('Signing in...');
113 if (e) {
114 e.preventDefault();
115 }
116
117 if (!email.current || !password.current) {
118 setRequiredError({
119 emailReq: email.current ? false : true,
120 passReq: password.current ? false : true,
121 });
122 toast.dismiss(loadId);
123 return;
124 }
125 setCheckingPassword(true);
126 const res = await signIn('credentials', {
127 username: email.current,
128 password: password.current,
129 redirect: false,
130 });
131
132 toast.dismiss(loadId);
133 if (!res?.error) {
134 router.push('/');
135 toast.success('Signed In');
136 } else {
137 if (res.status === 401) {
138 toast.error('Invalid Credentials, try again!');
139 } else if (res.status === 400) {
140 toast.error('Missing Credentials!');
141 } else if (res.status === 404) {
142 toast.error('Account not found!');
143 } else if (res.status === 403) {
144 toast.error('Forbidden!');
145 } else {
146 toast.error('oops something went wrong..!');
147 }
148 setCheckingPassword(false);
149 }
150 };
151
152 // Handle clicks outside the dropdown
153 useEffect(() => {

Callers 2

SigninFunction · 0.70
NewPayoutDialogFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected