({
setError,
setLoading,
state,
onSignIn,
callbackUrl,
sso,
}: {
setError: (arg: string) => void;
setLoading: (arg: boolean) => void;
state?: string;
onSignIn?: () => void;
callbackUrl?: string;
sso?: string;
})
| 175 | } |
| 176 | |
| 177 | export function onSignUpWithCredsSubmit({ |
| 178 | setError, |
| 179 | setLoading, |
| 180 | state, |
| 181 | onSignIn, |
| 182 | callbackUrl, |
| 183 | sso, |
| 184 | }: { |
| 185 | setError: (arg: string) => void; |
| 186 | setLoading: (arg: boolean) => void; |
| 187 | state?: string; |
| 188 | onSignIn?: () => void; |
| 189 | callbackUrl?: string; |
| 190 | sso?: string; |
| 191 | }) { |
| 192 | return async (event: any) => { |
| 193 | event.preventDefault(); |
| 194 | const form = event.target; |
| 195 | const email = form.email.value; |
| 196 | const password = form.password.value; |
| 197 | |
| 198 | if (!email) { |
| 199 | setError('Email is required'); |
| 200 | return; |
| 201 | } |
| 202 | if (!password) { |
| 203 | setError('Password is required'); |
| 204 | return; |
| 205 | } |
| 206 | try { |
| 207 | setLoading(true); |
| 208 | const thread = localStorage.get('nouser.thread'); |
| 209 | const message = localStorage.get('nouser.message'); |
| 210 | localStorage.remove('nouser.thread'); |
| 211 | localStorage.remove('nouser.message'); |
| 212 | const signUpResponse = await fetch('/api/signup', { |
| 213 | method: 'POST', |
| 214 | body: JSON.stringify({ |
| 215 | email: String(email).toLowerCase(), |
| 216 | password, |
| 217 | ...(!!state && { |
| 218 | accountId: state, |
| 219 | }), |
| 220 | ...(!!form.displayName.value && { |
| 221 | displayName: form.displayName.value, |
| 222 | }), |
| 223 | thread, |
| 224 | message, |
| 225 | }), |
| 226 | }); |
| 227 | if (!signUpResponse.ok) { |
| 228 | throw signUpResponse; |
| 229 | } |
| 230 | |
| 231 | const csrfToken = form?.csrfToken?.value || (await getCsrfToken()); |
| 232 | |
| 233 | const signInResponse = await signInWithCreds( |
| 234 | email, |
no test coverage detected