diff --git a/framework/kibocommerce/api/endpoints/login/login.ts b/framework/kibocommerce/api/endpoints/login/login.ts index f55c3b54f..d90a93457 100644 --- a/framework/kibocommerce/api/endpoints/login/login.ts +++ b/framework/kibocommerce/api/endpoints/login/login.ts @@ -9,6 +9,7 @@ const login: LoginEndpoint['handlers']['login'] = async ({ config, commerce, }) => { + console.log('login hit', email, password) // TODO: Add proper validations with something like Ajv if (!(email && password)) { return res.status(400).json({ @@ -16,12 +17,13 @@ const login: LoginEndpoint['handlers']['login'] = async ({ errors: [{ message: 'Invalid request' }], }) } - // TODO: validate the password and email - // Passwords must be at least 7 characters and contain both alphabetic - // and numeric characters. - try { - await commerce.login({ variables: { email, password }, config, res }) +/* +const loginMutation = ` mutation loginAccount($input) { login($input) { } } ` +const variables = { input: { email, password } } +const loginResponse = await config.fetch(loginMutation, { variables }) +setCookie(res) +*/ } catch (error) { // Check if the email and password didn't match an existing account if ( @@ -46,4 +48,4 @@ const login: LoginEndpoint['handlers']['login'] = async ({ res.status(200).json({ data: null }) } -export default login +export default login \ No newline at end of file diff --git a/framework/kibocommerce/auth/use-login.tsx b/framework/kibocommerce/auth/use-login.tsx index 60f8f4697..eec15965d 100644 --- a/framework/kibocommerce/auth/use-login.tsx +++ b/framework/kibocommerce/auth/use-login.tsx @@ -5,14 +5,14 @@ import { useCallback } from 'react' import { CommerceError } from '@commerce/utils/errors' import type { LoginHook } from '../types/login' import useCustomer from '../customer/use-customer' - +import { loginMutation } from '../utils/mutations/login-mutation' export default useLogin as UseLogin export const handler: MutationHook = { fetchOptions: { url: '/api/login', method: 'POST', - query: '' + query: loginMutation }, async fetcher({ input: { email, password }, options, fetch }) { if (!(email && password)) { diff --git a/framework/kibocommerce/utils/mutations/login-mutation.ts b/framework/kibocommerce/utils/mutations/login-mutation.ts new file mode 100644 index 000000000..b4b655cc3 --- /dev/null +++ b/framework/kibocommerce/utils/mutations/login-mutation.ts @@ -0,0 +1,19 @@ + +export const loginMutation = ` +mutation login($loginInput:CustomerUserAuthInfoInput!) { + account:createCustomerAuthTicket(customerUserAuthInfoInput:$loginInput) { + accessToken + userId + refreshToken + refreshTokenExpiration + customerAccount { + id + firstName + lastName + emailAddress + userName + } + } + } +` +