Gérard Le Cloerec 3f41969f5c feat: disable Wishlist
chore: setup commerce & next config
fix: replace all call to bigcommerce from aquilacms provider
feat add validation to input in signup
2021-04-06 15:08:19 +02:00

57 lines
1.3 KiB
TypeScript

import type { ServerResponse } from 'http'
import concatHeader from '../api/utils/concat-cookie'
import { AquilacmsConfig, getConfig } from '../api'
import { serialize } from 'cookie'
export type LoginResult<T extends { result?: any } = { result?: string }> = T
export type LoginVariables = { email: string; password: string }
async function login(opts: {
variables: LoginVariables
config?: AquilacmsConfig
res: ServerResponse
}): Promise<LoginResult>
async function login<T extends { result?: any }, V = any>(opts: {
query: string
variables: V
res: ServerResponse
config?: AquilacmsConfig
}): Promise<LoginResult<T>>
async function login({
variables,
res: response,
config,
}: {
query?: string
variables: LoginVariables
res: ServerResponse
config?: AquilacmsConfig
}): Promise<LoginResult> {
config = getConfig(config)
const { data, code: result } = await config.storeApiFetch('/v2/auth/login', {
method: 'POST',
body: JSON.stringify({
username: variables.email,
password: variables.password,
}),
})
response.setHeader(
'Set-Cookie',
concatHeader(
response.getHeader('Set-Cookie'),
serialize(config.customerCookie, data, { sameSite: 'lax', path: '/' })
)!
)
return {
result,
}
}
export default login