mirror of
https://github.com/vercel/commerce.git
synced 2025-05-20 00:16:59 +00:00
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import type { ServerResponse } from 'http'
|
|
import type { OperationContext } from '@commerce/api/operations'
|
|
import type { Provider, SaleorConfig } from '..'
|
|
import { throwUserErrors } from '../../utils'
|
|
|
|
import * as Mutation from '../../utils/mutations'
|
|
|
|
export default function loginOperation({ commerce }: OperationContext<Provider>) {
|
|
async function login({
|
|
query = Mutation.SessionCreate,
|
|
variables,
|
|
config,
|
|
}: {
|
|
query?: string
|
|
variables: any
|
|
res: ServerResponse
|
|
config?: SaleorConfig
|
|
}): Promise<any> {
|
|
config = commerce.getConfig(config)
|
|
|
|
const {
|
|
data: { customerAccessTokenCreate },
|
|
} = await config.fetch(query, { variables })
|
|
|
|
throwUserErrors(customerAccessTokenCreate?.customerUserErrors)
|
|
|
|
const customerAccessToken = customerAccessTokenCreate?.customerAccessToken
|
|
const accessToken = customerAccessToken?.accessToken
|
|
|
|
// if (accessToken) {
|
|
// setCustomerToken(accessToken)
|
|
// }
|
|
|
|
return {
|
|
result: customerAccessToken?.accessToken,
|
|
}
|
|
}
|
|
|
|
return login
|
|
}
|