From 4cdce5ed392689edb98fc9341036e7ebbca19de7 Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 10:28:44 +0530 Subject: [PATCH 1/8] Initial Commit --- components/common/UserNav/UserNav.tsx | 4 +- .../kibocommerce/api/endpoints/login/index.ts | 22 ++++++++- .../kibocommerce/api/endpoints/login/login.ts | 49 +++++++++++++++++++ framework/kibocommerce/auth/use-login.tsx | 38 +++++++++++--- framework/kibocommerce/commerce.config.json | 4 +- framework/kibocommerce/schema.d.ts | 5 ++ framework/kibocommerce/types/login.ts | 8 +++ 7 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 framework/kibocommerce/api/endpoints/login/login.ts create mode 100644 framework/kibocommerce/types/login.ts diff --git a/components/common/UserNav/UserNav.tsx b/components/common/UserNav/UserNav.tsx index 5d7d28df3..07e1af04d 100644 --- a/components/common/UserNav/UserNav.tsx +++ b/components/common/UserNav/UserNav.tsx @@ -40,7 +40,7 @@ const UserNav: FC = ({ className }) => { )} - {process.env.COMMERCE_CUSTOMERAUTH_ENABLED && ( +
  • {customer ? ( @@ -54,7 +54,7 @@ const UserNav: FC = ({ className }) => { )}
  • - )} + ) diff --git a/framework/kibocommerce/api/endpoints/login/index.ts b/framework/kibocommerce/api/endpoints/login/index.ts index 491bf0ac9..ed3200058 100644 --- a/framework/kibocommerce/api/endpoints/login/index.ts +++ b/framework/kibocommerce/api/endpoints/login/index.ts @@ -1 +1,21 @@ -export default function noopApi(...args: any[]): void {} +// export default function noopApi(...args: any[]): void {} + +import { GetAPISchema, createEndpoint } from '@commerce/api' +import loginEndpoint from '@commerce/api/endpoints/login' +import type { LoginSchema } from '../../../types/login' +import type { KiboCommerceAPI } from '../..' +import login from './login' + +export type LoginAPI = GetAPISchema + +export type LoginEndpoint = LoginAPI['endpoint'] + +export const handlers: LoginEndpoint['handlers'] = { login } + +const loginApi = createEndpoint({ + handler: loginEndpoint, + handlers, +}) + +export default loginApi + diff --git a/framework/kibocommerce/api/endpoints/login/login.ts b/framework/kibocommerce/api/endpoints/login/login.ts new file mode 100644 index 000000000..f55c3b54f --- /dev/null +++ b/framework/kibocommerce/api/endpoints/login/login.ts @@ -0,0 +1,49 @@ +import { FetcherError } from '@commerce/utils/errors' +import type { LoginEndpoint } from '.' + +const invalidCredentials = /invalid credentials/i + +const login: LoginEndpoint['handlers']['login'] = async ({ + res, + body: { email, password }, + config, + commerce, +}) => { + // TODO: Add proper validations with something like Ajv + if (!(email && password)) { + return res.status(400).json({ + data: null, + 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 }) + } catch (error) { + // Check if the email and password didn't match an existing account + if ( + error instanceof FetcherError && + invalidCredentials.test(error.message) + ) { + return res.status(401).json({ + data: null, + errors: [ + { + message: + 'Cannot find an account that matches the provided credentials', + code: 'invalid_credentials', + }, + ], + }) + } + + throw error + } + + res.status(200).json({ data: null }) +} + +export default login diff --git a/framework/kibocommerce/auth/use-login.tsx b/framework/kibocommerce/auth/use-login.tsx index 28351dc7f..60f8f4697 100644 --- a/framework/kibocommerce/auth/use-login.tsx +++ b/framework/kibocommerce/auth/use-login.tsx @@ -1,16 +1,42 @@ import { MutationHook } from '@commerce/utils/types' import useLogin, { UseLogin } from '@commerce/auth/use-login' +import { useCallback } from 'react' +import { CommerceError } from '@commerce/utils/errors' +import type { LoginHook } from '../types/login' +import useCustomer from '../customer/use-customer' + export default useLogin as UseLogin -export const handler: MutationHook = { +export const handler: MutationHook = { fetchOptions: { - query: '', + url: '/api/login', + method: 'POST', + query: '' }, - async fetcher() { - return null + async fetcher({ input: { email, password }, options, fetch }) { + if (!(email && password)) { + throw new CommerceError({ + message: + 'An email and password are required to login', + }) + } + + return fetch({ + ...options, + body: { email, password }, + }) }, - useHook: () => () => { - return async function () {} + useHook: ({ fetch }) => () => { + const { revalidate } = useCustomer() + + return useCallback( + async function login(input) { + const data = await fetch({ input }) + // await revalidate() + return data + }, + [fetch, revalidate] + ) }, } diff --git a/framework/kibocommerce/commerce.config.json b/framework/kibocommerce/commerce.config.json index 0871b8849..8992569c6 100644 --- a/framework/kibocommerce/commerce.config.json +++ b/framework/kibocommerce/commerce.config.json @@ -4,6 +4,6 @@ "wishlist": false, "cart": false, "search": false, - "customerAuth": false + "customerAuth": true } -} +} \ No newline at end of file diff --git a/framework/kibocommerce/schema.d.ts b/framework/kibocommerce/schema.d.ts index cf52ddec9..430ce10b9 100644 --- a/framework/kibocommerce/schema.d.ts +++ b/framework/kibocommerce/schema.d.ts @@ -11397,3 +11397,8 @@ export type WorkflowStateInput = { shipmentState?: Maybe taskList?: Maybe>> } + +export type LoginMutationVariables = Exact<{ + email: Scalars['String'] + password: Scalars['String'] +}> \ No newline at end of file diff --git a/framework/kibocommerce/types/login.ts b/framework/kibocommerce/types/login.ts new file mode 100644 index 000000000..24d5077ff --- /dev/null +++ b/framework/kibocommerce/types/login.ts @@ -0,0 +1,8 @@ +import * as Core from '@commerce/types/login' +import type { LoginMutationVariables } from '../schema' + +export * from '@commerce/types/login' + +export type LoginOperation = Core.LoginOperation & { + variables: LoginMutationVariables +} From 37bce41ec6fb1a07a948b2ffa47a9b107f273c16 Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 10:39:47 +0530 Subject: [PATCH 2/8] Commited Keys --- framework/kibocommerce/api/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/kibocommerce/api/index.ts b/framework/kibocommerce/api/index.ts index 3999d6b48..9686519d3 100644 --- a/framework/kibocommerce/api/index.ts +++ b/framework/kibocommerce/api/index.ts @@ -12,10 +12,10 @@ import getProduct from './operations/get-product' export interface KiboCommerceConfig extends CommerceAPIConfig {} const config: KiboCommerceConfig = { - commerceUrl: process.env.KIBO_API_URL || '', - apiToken: process.env.KIBO_API_TOKEN || '', - cartCookie: process.env.KIBO_CART_COOKIE || '', - customerCookie: process.env.KIBO_CUSTOMER_COOKIE || '', + commerceUrl: process.env.KIBO_API_URL || 'https://t17194-s21127.dev10.kubedev.kibo-dev.com/graphql', + apiToken: process.env.KIBO_API_TOKEN || `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL3d3dy5raWJvY29tbWVyY2UuY29tL2FwcF9jbGFpbXMiOnsic3NsIjoiMCIsImVudCI6IjEiLCJtdHIiOiIxIiwidWMiOiIwIiwicm5kIjoxNDQ1NjE5MDQ0LCJhaWQiOiJraWJvLWRldmVsb3Blci1rZXkiLCJha2V5Ijoia2liby1kZXZlbG9wZXIta2V5IiwiYnYiOlswLC0xNTc3NzkyMiwxLDIwNzkwNjQwNjMsMiwyMTQ3NDgzNTgyLDMsLTk3LDQsODE5MSw1LC0xNzE1Myw2LC0xMzQyMTc3MjksNywtMSw4LDQxOTQzMDMsMzEsODM4ODM1Ml0sImV4cCI6IjIwMjYtMDQtMjlUMTg6NDA6MDQiLCJlbnYiOiJkZXYxMCJ9LCJuYmYiOjE2MTk3MjE2MDUsImV4cCI6MTc3NzQ4ODAwNCwiaWF0IjoxNjE5NzIxNjA1LCJpc3MiOiJodHRwczovL3d3dy5raWJvY29tbWVyY2UuY29tIiwiYXVkIjoiaHR0cHM6Ly93d3cua2lib2NvbW1lcmNlLmNvbSJ9.xn2i0-1bmH65x_z51UQVRDY8fwn4NXnnD5JtIhcrUkw`, + cartCookie: process.env.KIBO_CART_COOKIE || 'kibo_car', + customerCookie: process.env.KIBO_CUSTOMER_COOKIE || 'kibo_customer', cartCookieMaxAge: 2592000, fetch: createFetcher(() => getCommerceApi().getConfig()), } From 05021b55290460966a912f2a991498d8e13438e0 Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 11:58:21 +0530 Subject: [PATCH 3/8] GraphQL Changes --- framework/kibocommerce/api/index.ts | 4 ++-- framework/kibocommerce/api/utils/fetch-local.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/framework/kibocommerce/api/index.ts b/framework/kibocommerce/api/index.ts index 9686519d3..3f6c9dd47 100644 --- a/framework/kibocommerce/api/index.ts +++ b/framework/kibocommerce/api/index.ts @@ -1,6 +1,6 @@ import type { CommerceAPI, CommerceAPIConfig } from '@commerce/api' import { getCommerceApi as commerceApi } from '@commerce/api' -import createFetcher from './utils/fetch-local' +import fetchGraphqlApi from './utils/fetch-local' import getAllPages from './operations/get-all-pages' import getPage from './operations/get-page' @@ -17,7 +17,7 @@ const config: KiboCommerceConfig = { cartCookie: process.env.KIBO_CART_COOKIE || 'kibo_car', customerCookie: process.env.KIBO_CUSTOMER_COOKIE || 'kibo_customer', cartCookieMaxAge: 2592000, - fetch: createFetcher(() => getCommerceApi().getConfig()), + fetch: fetchGraphqlApi(() => getCommerceApi().getConfig()), } const operations = { diff --git a/framework/kibocommerce/api/utils/fetch-local.ts b/framework/kibocommerce/api/utils/fetch-local.ts index e6ad35ba2..2612188a9 100644 --- a/framework/kibocommerce/api/utils/fetch-local.ts +++ b/framework/kibocommerce/api/utils/fetch-local.ts @@ -8,9 +8,11 @@ const fetchGraphqlApi: (getConfig: () => KiboCommerceConfig) => GraphQLFetcher = async (query: string, { variables, preview } = {}, fetchOptions) => { const config = getConfig() const res = await fetch(config.commerceUrl, { + //const res = await fetch(config.commerceUrl + (preview ? '/preview' : ''), { ...fetchOptions, method: 'POST', headers: { + Authorization: `Bearer ${config.apiToken}`, ...fetchOptions?.headers, 'Content-Type': 'application/json', }, @@ -23,7 +25,7 @@ const fetchGraphqlApi: (getConfig: () => KiboCommerceConfig) => GraphQLFetcher = const json = await res.json() if (json.errors) { throw new FetcherError({ - errors: json.errors ?? [{ message: 'Failed to fetch for API' }], + errors: json.errors ?? [{ message: 'Failed to fetch KiboCommerce API' }], status: res.status, }) } From 56dbee6955d2779e01da9403a70cc4af704c093b Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 16:09:47 +0530 Subject: [PATCH 4/8] GraphQL Query --- .../kibocommerce/api/endpoints/login/login.ts | 14 ++++++++------ framework/kibocommerce/auth/use-login.tsx | 4 ++-- .../utils/mutations/login-mutation.ts | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 framework/kibocommerce/utils/mutations/login-mutation.ts 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 + } + } + } +` + From c71b2fb14da768941bf6f7e138d376a834a31318 Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 17:57:46 +0530 Subject: [PATCH 5/8] Final Changes --- .../kibocommerce/api/endpoints/login/index.ts | 3 +- .../kibocommerce/api/endpoints/login/login.ts | 28 +++++++++++++------ .../api/utils/prepareSetCookie.ts | 13 +++++++++ framework/kibocommerce/api/utils/setCookie.ts | 3 ++ framework/kibocommerce/auth/use-login.tsx | 4 +-- .../utils/mutations/login-mutation.ts | 1 + 6 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 framework/kibocommerce/api/utils/prepareSetCookie.ts create mode 100644 framework/kibocommerce/api/utils/setCookie.ts diff --git a/framework/kibocommerce/api/endpoints/login/index.ts b/framework/kibocommerce/api/endpoints/login/index.ts index ed3200058..49476c7f6 100644 --- a/framework/kibocommerce/api/endpoints/login/index.ts +++ b/framework/kibocommerce/api/endpoints/login/index.ts @@ -12,10 +12,9 @@ export type LoginEndpoint = LoginAPI['endpoint'] export const handlers: LoginEndpoint['handlers'] = { login } -const loginApi = createEndpoint({ +export const loginApi = createEndpoint({ handler: loginEndpoint, handlers, }) -export default loginApi diff --git a/framework/kibocommerce/api/endpoints/login/login.ts b/framework/kibocommerce/api/endpoints/login/login.ts index d90a93457..699fa0fbf 100644 --- a/framework/kibocommerce/api/endpoints/login/login.ts +++ b/framework/kibocommerce/api/endpoints/login/login.ts @@ -1,16 +1,21 @@ import { FetcherError } from '@commerce/utils/errors' import type { LoginEndpoint } from '.' +import { loginMutation } from '../../../utils/mutations/login-mutation' +import {prepareSetCookie} from '../../utils/prepareSetCookie'; +import {setCookies} from '../../utils/setCookie' const invalidCredentials = /invalid credentials/i +let response; + const login: LoginEndpoint['handlers']['login'] = async ({ + req, res, body: { email, password }, config, commerce, }) => { - console.log('login hit', email, password) - // TODO: Add proper validations with something like Ajv + if (!(email && password)) { return res.status(400).json({ data: null, @@ -18,12 +23,17 @@ const login: LoginEndpoint['handlers']['login'] = async ({ }) } try { -/* -const loginMutation = ` mutation loginAccount($input) { login($input) { } } ` -const variables = { input: { email, password } } -const loginResponse = await config.fetch(loginMutation, { variables }) -setCookie(res) -*/ + + response = await config.fetch(loginMutation, { variables: { loginInput : { username: email, password }}}) + const { account } = response.data; + + const authCookie = prepareSetCookie( + config.customerCookie, + JSON.stringify(response.data.account), + account.accessTokenExpiration ? { expires: new Date(account.accessTokenExpiration) }: {}, + ) + setCookies(res, [authCookie]) + } catch (error) { // Check if the email and password didn't match an existing account if ( @@ -45,7 +55,7 @@ setCookie(res) throw error } - res.status(200).json({ data: null }) + res.status(200).json({ data: response }) } export default login \ No newline at end of file diff --git a/framework/kibocommerce/api/utils/prepareSetCookie.ts b/framework/kibocommerce/api/utils/prepareSetCookie.ts new file mode 100644 index 000000000..3d9b3380a --- /dev/null +++ b/framework/kibocommerce/api/utils/prepareSetCookie.ts @@ -0,0 +1,13 @@ +export function prepareSetCookie(name: string, value: string, options: any = {}): string { + const cookieValue = [`${name}=${value}`]; + + if (options.maxAge) { + cookieValue.push(`Max-Age=${options.maxAge}`); + } + + if (options.expires && !options.maxAge) { + cookieValue.push(`Expires=${options.expires.toUTCString()}`); + } + + return cookieValue.join('; '); +} \ No newline at end of file diff --git a/framework/kibocommerce/api/utils/setCookie.ts b/framework/kibocommerce/api/utils/setCookie.ts new file mode 100644 index 000000000..2c194c921 --- /dev/null +++ b/framework/kibocommerce/api/utils/setCookie.ts @@ -0,0 +1,3 @@ +export function setCookies(res: any, cookies: string[]): void { + res.setHeader('Set-Cookie', cookies); +} \ No newline at end of file diff --git a/framework/kibocommerce/auth/use-login.tsx b/framework/kibocommerce/auth/use-login.tsx index eec15965d..c0197e4c2 100644 --- a/framework/kibocommerce/auth/use-login.tsx +++ b/framework/kibocommerce/auth/use-login.tsx @@ -5,14 +5,12 @@ 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: loginMutation + method: 'POST' }, 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 index b4b655cc3..61a9d03a5 100644 --- a/framework/kibocommerce/utils/mutations/login-mutation.ts +++ b/framework/kibocommerce/utils/mutations/login-mutation.ts @@ -6,6 +6,7 @@ mutation login($loginInput:CustomerUserAuthInfoInput!) { userId refreshToken refreshTokenExpiration + accessTokenExpiration customerAccount { id firstName From 3fde09ef17d4e610c62622bbfa37ad1fffe4188c Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 17:58:11 +0530 Subject: [PATCH 6/8] Changed login.ts --- pages/api/login.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/login.ts b/pages/api/login.ts index 9d0b6ae57..474209523 100644 --- a/pages/api/login.ts +++ b/pages/api/login.ts @@ -1,4 +1,4 @@ -import loginApi from '@framework/api/endpoints/login' +import { loginApi } from '@framework/api/endpoints/login' import commerce from '@lib/api/commerce' export default loginApi(commerce) From ae4c1b85b49c69ebfcfe0c06168bf17bf46a6978 Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 18:36:14 +0530 Subject: [PATCH 7/8] Made changes in login.ts --- framework/kibocommerce/api/endpoints/login/login.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/kibocommerce/api/endpoints/login/login.ts b/framework/kibocommerce/api/endpoints/login/login.ts index 699fa0fbf..27ac8c86b 100644 --- a/framework/kibocommerce/api/endpoints/login/login.ts +++ b/framework/kibocommerce/api/endpoints/login/login.ts @@ -29,7 +29,7 @@ const login: LoginEndpoint['handlers']['login'] = async ({ const authCookie = prepareSetCookie( config.customerCookie, - JSON.stringify(response.data.account), + JSON.stringify(account), account.accessTokenExpiration ? { expires: new Date(account.accessTokenExpiration) }: {}, ) setCookies(res, [authCookie]) From d408c8f5850d0b0afab7fc73f57ef5dd88404037 Mon Sep 17 00:00:00 2001 From: SushantJadhav Date: Wed, 25 Aug 2021 20:14:51 +0530 Subject: [PATCH 8/8] Final Changes --- .../kibocommerce/api/endpoints/login/login.ts | 15 ++++++++------- .../{utils => api}/mutations/login-mutation.ts | 0 .../{api/utils => lib}/prepareSetCookie.ts | 0 .../kibocommerce/{api/utils => lib}/setCookie.ts | 0 4 files changed, 8 insertions(+), 7 deletions(-) rename framework/kibocommerce/{utils => api}/mutations/login-mutation.ts (100%) rename framework/kibocommerce/{api/utils => lib}/prepareSetCookie.ts (100%) rename framework/kibocommerce/{api/utils => lib}/setCookie.ts (100%) diff --git a/framework/kibocommerce/api/endpoints/login/login.ts b/framework/kibocommerce/api/endpoints/login/login.ts index 27ac8c86b..eb882d998 100644 --- a/framework/kibocommerce/api/endpoints/login/login.ts +++ b/framework/kibocommerce/api/endpoints/login/login.ts @@ -1,8 +1,9 @@ +import Cookies from 'js-cookie' import { FetcherError } from '@commerce/utils/errors' import type { LoginEndpoint } from '.' -import { loginMutation } from '../../../utils/mutations/login-mutation' -import {prepareSetCookie} from '../../utils/prepareSetCookie'; -import {setCookies} from '../../utils/setCookie' +import { loginMutation } from '../../mutations/login-mutation' +import {prepareSetCookie} from '../../../lib/prepareSetCookie'; +import {setCookies} from '../../../lib/setCookie' const invalidCredentials = /invalid credentials/i @@ -25,15 +26,15 @@ const login: LoginEndpoint['handlers']['login'] = async ({ try { response = await config.fetch(loginMutation, { variables: { loginInput : { username: email, password }}}) - const { account } = response.data; + const { account: token } = response.data; const authCookie = prepareSetCookie( config.customerCookie, - JSON.stringify(account), - account.accessTokenExpiration ? { expires: new Date(account.accessTokenExpiration) }: {}, + JSON.stringify(token), + token.accessTokenExpiration ? { expires: new Date(token.accessTokenExpiration) }: {}, ) setCookies(res, [authCookie]) - + } catch (error) { // Check if the email and password didn't match an existing account if ( diff --git a/framework/kibocommerce/utils/mutations/login-mutation.ts b/framework/kibocommerce/api/mutations/login-mutation.ts similarity index 100% rename from framework/kibocommerce/utils/mutations/login-mutation.ts rename to framework/kibocommerce/api/mutations/login-mutation.ts diff --git a/framework/kibocommerce/api/utils/prepareSetCookie.ts b/framework/kibocommerce/lib/prepareSetCookie.ts similarity index 100% rename from framework/kibocommerce/api/utils/prepareSetCookie.ts rename to framework/kibocommerce/lib/prepareSetCookie.ts diff --git a/framework/kibocommerce/api/utils/setCookie.ts b/framework/kibocommerce/lib/setCookie.ts similarity index 100% rename from framework/kibocommerce/api/utils/setCookie.ts rename to framework/kibocommerce/lib/setCookie.ts