mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 20:21:21 +00:00
GraphQL Query
This commit is contained in:
parent
05021b5529
commit
56dbee6955
@ -9,6 +9,7 @@ const login: LoginEndpoint['handlers']['login'] = async ({
|
|||||||
config,
|
config,
|
||||||
commerce,
|
commerce,
|
||||||
}) => {
|
}) => {
|
||||||
|
console.log('login hit', email, password)
|
||||||
// TODO: Add proper validations with something like Ajv
|
// TODO: Add proper validations with something like Ajv
|
||||||
if (!(email && password)) {
|
if (!(email && password)) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@ -16,12 +17,13 @@ const login: LoginEndpoint['handlers']['login'] = async ({
|
|||||||
errors: [{ message: 'Invalid request' }],
|
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 {
|
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) {
|
} catch (error) {
|
||||||
// Check if the email and password didn't match an existing account
|
// Check if the email and password didn't match an existing account
|
||||||
if (
|
if (
|
||||||
|
@ -5,14 +5,14 @@ import { useCallback } from 'react'
|
|||||||
import { CommerceError } from '@commerce/utils/errors'
|
import { CommerceError } from '@commerce/utils/errors'
|
||||||
import type { LoginHook } from '../types/login'
|
import type { LoginHook } from '../types/login'
|
||||||
import useCustomer from '../customer/use-customer'
|
import useCustomer from '../customer/use-customer'
|
||||||
|
import { loginMutation } from '../utils/mutations/login-mutation'
|
||||||
export default useLogin as UseLogin<typeof handler>
|
export default useLogin as UseLogin<typeof handler>
|
||||||
|
|
||||||
export const handler: MutationHook<LoginHook> = {
|
export const handler: MutationHook<LoginHook> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
url: '/api/login',
|
url: '/api/login',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
query: ''
|
query: loginMutation
|
||||||
},
|
},
|
||||||
async fetcher({ input: { email, password }, options, fetch }) {
|
async fetcher({ input: { email, password }, options, fetch }) {
|
||||||
if (!(email && password)) {
|
if (!(email && password)) {
|
||||||
|
19
framework/kibocommerce/utils/mutations/login-mutation.ts
Normal file
19
framework/kibocommerce/utils/mutations/login-mutation.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user