Refactored login.ts

This commit is contained in:
SushantJadhav 2021-08-26 08:17:44 +05:30
parent a122d68a2c
commit e79821bdae

View File

@ -25,16 +25,17 @@ const login: LoginEndpoint['handlers']['login'] = async ({
} }
try { try {
response = await config.fetch(loginMutation, { variables: { loginInput : { username: email, password }}}) const variables = { loginInput : { username: email, password }};
response = await config.fetch(loginMutation, { variables: variables})
const { account: token } = response.data; const { account: token } = response.data;
const authCookie = prepareSetCookie( const authCookie = prepareSetCookie(
config.customerCookie, config.customerCookie,
JSON.stringify(token), JSON.stringify(token),
token.accessTokenExpiration ? { expires: new Date(token.accessTokenExpiration) }: {}, token.accessTokenExpiration ? { expires: new Date(token.accessTokenExpiration) }: {},
) )
setCookies(res, [authCookie]) setCookies(res, [authCookie])
} 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 (