Added useLogin hook and API endpoint

This commit is contained in:
Luis Alvarez
2020-10-20 22:27:38 -05:00
parent e2b26715b9
commit a1e47a73d2
9 changed files with 132 additions and 6 deletions

View File

@@ -57,6 +57,7 @@ const createCustomer: CustomersHandlers['createCustomer'] = async ({
console.log('DATA', result.data)
// TODO: Currently not working, fix this asap.
const loginData = await login({ variables: { email, password }, config })
console.log('LOGIN DATA', loginData)

View File

@@ -0,0 +1,26 @@
import login from '../../operations/login'
import type { LoginHandlers } from '../login'
const loginHandler: LoginHandlers['login'] = async ({
res,
body: { email, password },
config,
}) => {
// TODO: Add proper validations with something like Ajv
if (!(email && password)) {
return res.status(400).json({
data: null,
errors: [{ message: 'Invalid request' }],
})
}
// TODO: validate the password and email
// Passwords must be at least 7 characters and contain both alphabetic
// and numeric characters.
// TODO: Currently not working, fix this asap.
const loginData = await login({ variables: { email, password }, config })
res.status(200).json({ data: null })
}
export default loginHandler