mirror of
https://github.com/vercel/commerce.git
synced 2025-07-07 13:21:22 +00:00
Final Changes
This commit is contained in:
parent
ae4c1b85b4
commit
d408c8f585
@ -1,8 +1,9 @@
|
|||||||
|
import Cookies from 'js-cookie'
|
||||||
import { FetcherError } from '@commerce/utils/errors'
|
import { FetcherError } from '@commerce/utils/errors'
|
||||||
import type { LoginEndpoint } from '.'
|
import type { LoginEndpoint } from '.'
|
||||||
import { loginMutation } from '../../../utils/mutations/login-mutation'
|
import { loginMutation } from '../../mutations/login-mutation'
|
||||||
import {prepareSetCookie} from '../../utils/prepareSetCookie';
|
import {prepareSetCookie} from '../../../lib/prepareSetCookie';
|
||||||
import {setCookies} from '../../utils/setCookie'
|
import {setCookies} from '../../../lib/setCookie'
|
||||||
|
|
||||||
const invalidCredentials = /invalid credentials/i
|
const invalidCredentials = /invalid credentials/i
|
||||||
|
|
||||||
@ -25,12 +26,12 @@ const login: LoginEndpoint['handlers']['login'] = async ({
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
response = await config.fetch(loginMutation, { variables: { loginInput : { username: email, password }}})
|
response = await config.fetch(loginMutation, { variables: { loginInput : { username: email, password }}})
|
||||||
const { account } = response.data;
|
const { account: token } = response.data;
|
||||||
|
|
||||||
const authCookie = prepareSetCookie(
|
const authCookie = prepareSetCookie(
|
||||||
config.customerCookie,
|
config.customerCookie,
|
||||||
JSON.stringify(account),
|
JSON.stringify(token),
|
||||||
account.accessTokenExpiration ? { expires: new Date(account.accessTokenExpiration) }: {},
|
token.accessTokenExpiration ? { expires: new Date(token.accessTokenExpiration) }: {},
|
||||||
)
|
)
|
||||||
setCookies(res, [authCookie])
|
setCookies(res, [authCookie])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user