Connected signing up and signing in to back

This commit is contained in:
2023-07-29 10:41:54 +03:00
parent 0e5aeae491
commit 85472233a3
14 changed files with 228 additions and 168 deletions

View File

@ -0,0 +1,31 @@
import { useSendWithButton } from '..'
import { composeTokenURL, processToken } from '../../api/token'
import { isTokenResponse } from '../../api/token/types'
import { setToken } from '../../utils/auth'
function useSignIn() {
const { doSend, button } = useSendWithButton(
'Войти',
'Войдено',
false,
composeTokenURL(),
'POST',
false,
isTokenResponse,
processToken,
)
async function handleSignIn(formData: FormData) {
const token = await doSend({}, {
body: formData
})
if (token !== undefined) {
setToken(token)
}
}
return { handleSignIn, signInButton: button }
}
export default useSignIn