diff --git a/packages/peregrine/lib/store/actions/user/asyncActions.js b/packages/peregrine/lib/store/actions/user/asyncActions.js index 266183117f..d3a2ccdb25 100755 --- a/packages/peregrine/lib/store/actions/user/asyncActions.js +++ b/packages/peregrine/lib/store/actions/user/asyncActions.js @@ -63,13 +63,13 @@ export const resetPassword = ({ email }) => dispatch(actions.resetPassword.receive()); }; -export const setToken = token => +export const setToken = (token, customer_token_lifetime = 3600) => async function thunk(...args) { const [dispatch] = args; // Store token in local storage. // TODO: Get correct token expire time from API - storage.setItem('signin_token', token, 3600); + storage.setItem('signin_token', token, customer_token_lifetime); // Persist in store dispatch(actions.setToken(token)); diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js index c8c4cb722a..f84bbc00a8 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js @@ -78,13 +78,19 @@ const signInVariables = { password: '123456' }; const authToken = 'auth-token-123'; +const customerTokenLifetime = 3600; const signInMock = { request: { query: defaultOperations.signInMutation, variables: signInVariables }, result: { - data: { generateCustomerToken: { token: authToken } } + data: { + generateCustomerToken: { + token: authToken, + customer_token_lifetime: customerTokenLifetime + } + } } }; @@ -202,7 +208,7 @@ describe('handle submit event', () => { await result.current.handleSubmit(formValues); }); - expect(mockSetToken).toHaveBeenCalledWith('auth-token-123'); + expect(mockSetToken).toHaveBeenCalledWith('auth-token-123', 3600); expect(createAccount).toHaveBeenCalled(); expect(mockRemoveCart).toHaveBeenCalled(); expect(mockCreateCart).toHaveBeenCalledWith({ diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js index 0fc86f1063..6787d4682f 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js @@ -44,6 +44,7 @@ export const SIGN_IN = gql` mutation SignInAfterCheckout($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token + customer_token_lifetime } } `; diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js index e1b45e9297..ef3a6d6169 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js @@ -117,7 +117,13 @@ export const useCreateAccount = props => { ...recaptchaDataForSignIn }); const token = signInResponse.data.generateCustomerToken.token; - await setToken(token); + const customerTokenLifetime = + signInResponse.data.generateCustomerToken + .customer_token_lifetime; + + await (customerTokenLifetime + ? setToken(token, customerTokenLifetime) + : setToken(token)); // Clear guest cart from redux. await removeCart(); diff --git a/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js b/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js index 4d60520b10..01dbabe7a7 100644 --- a/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js +++ b/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js @@ -102,7 +102,8 @@ const signInMutationFn = jest.fn().mockReturnValue([ jest.fn().mockReturnValue({ data: { generateCustomerToken: { - token: 'customer token' + token: 'customer token', + customer_token_lifetime: 3600 } } }), @@ -272,10 +273,12 @@ describe('handleSubmit', () => { test('should signin after account creation', async () => { const token = 'customertoken'; + const customer_token_lifetime = 3600; const signIn = jest.fn().mockReturnValue({ data: { generateCustomerToken: { - token + token, + customer_token_lifetime } } }); @@ -298,7 +301,7 @@ describe('handleSubmit', () => { password: defaultFormValues.password } }); - expect(setToken).toHaveBeenCalledWith(token); + expect(setToken).toHaveBeenCalledWith(token, customer_token_lifetime); }); test('should clear cart data from cache', async () => { diff --git a/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js b/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js index 4f4ecf9b26..4eed9375f0 100644 --- a/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js +++ b/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js @@ -45,6 +45,7 @@ export const SIGN_IN = gql` mutation SignInAfterCreate($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token + customer_token_lifetime } } `; diff --git a/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js b/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js index cc8953998a..5bfca3e6bc 100644 --- a/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js +++ b/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js @@ -136,8 +136,12 @@ export const useCreateAccount = props => { ...recaptchaDataForSignIn }); const token = signInResponse.data.generateCustomerToken.token; - await setToken(token); - + const customerTokenLifetime = + signInResponse.data.generateCustomerToken + .customer_token_lifetime; + await (customerTokenLifetime + ? setToken(token, customerTokenLifetime) + : setToken(token)); // Clear all cart/customer data from cache and redux. await apolloClient.clearCacheData(apolloClient, 'cart'); await apolloClient.clearCacheData(apolloClient, 'customer'); diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index 63e35adb8b..e32b6b1c4f 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -61,6 +61,7 @@ const signInVariables = { password: 'slurm is the best' }; const authToken = 'auth-token-123'; +const customerTokenLifetime = 3600; const signInMock = { request: { @@ -68,7 +69,12 @@ const signInMock = { variables: signInVariables }, result: { - data: { generateCustomerToken: { token: authToken } } + data: { + generateCustomerToken: { + token: authToken, + customer_token_lifetime: customerTokenLifetime + } + } } }; @@ -156,7 +162,7 @@ test('handleSubmit triggers waterfall of operations and actions', async () => { await act(() => result.current.handleSubmit(signInVariables)); expect(result.current.isBusy).toBe(true); - expect(setToken).toHaveBeenCalledWith(authToken); + expect(setToken).toHaveBeenCalledWith(authToken, customerTokenLifetime); expect(getCartDetails).toHaveBeenCalled(); expect(getUserDetails).toHaveBeenCalled(); diff --git a/packages/peregrine/lib/talons/SignIn/signIn.gql.js b/packages/peregrine/lib/talons/SignIn/signIn.gql.js index 4aeb05a536..b960c3452e 100644 --- a/packages/peregrine/lib/talons/SignIn/signIn.gql.js +++ b/packages/peregrine/lib/talons/SignIn/signIn.gql.js @@ -17,6 +17,7 @@ export const SIGN_IN = gql` mutation SignIn($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token + customer_token_lifetime } } `; diff --git a/packages/peregrine/lib/talons/SignIn/useSignIn.js b/packages/peregrine/lib/talons/SignIn/useSignIn.js index 0bf326e531..35d80fe896 100644 --- a/packages/peregrine/lib/talons/SignIn/useSignIn.js +++ b/packages/peregrine/lib/talons/SignIn/useSignIn.js @@ -86,7 +86,13 @@ export const useSignIn = props => { }); const token = signInResponse.data.generateCustomerToken.token; - await setToken(token); + const customerTokenLifetime = + signInResponse.data.generateCustomerToken + .customer_token_lifetime; + + await (customerTokenLifetime + ? setToken(token, customerTokenLifetime) + : setToken(token)); // Clear all cart/customer data from cache and redux. await apolloClient.clearCacheData(apolloClient, 'cart'); diff --git a/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js b/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js index 3416d6ef55..d367072695 100644 --- a/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js +++ b/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js @@ -15,7 +15,7 @@ const thisDep = { intercept }; -const WEBPACK_BUILD_TIMEOUT = 30000; +const WEBPACK_BUILD_TIMEOUT = 800000; const mockComponent = name => `function ${name}(props) { return