Skip to content

Commit 2614c63

Browse files
authored
PWA-3236: Change user time to logout (#4260)
* PWA-3236: Change user time to logout * PWA-3263: Change user logout time * PWA-3263:change user logout time * increasing the time of build pack * increasing the time of build pack
1 parent 6116252 commit 2614c63

File tree

11 files changed

+48
-14
lines changed

11 files changed

+48
-14
lines changed

packages/peregrine/lib/store/actions/user/asyncActions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ export const resetPassword = ({ email }) =>
6363
dispatch(actions.resetPassword.receive());
6464
};
6565

66-
export const setToken = token =>
66+
export const setToken = (token, customer_token_lifetime = 3600) =>
6767
async function thunk(...args) {
6868
const [dispatch] = args;
6969

7070
// Store token in local storage.
7171
// TODO: Get correct token expire time from API
72-
storage.setItem('signin_token', token, 3600);
72+
storage.setItem('signin_token', token, customer_token_lifetime);
7373

7474
// Persist in store
7575
dispatch(actions.setToken(token));

packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,19 @@ const signInVariables = {
7878
password: '123456'
7979
};
8080
const authToken = 'auth-token-123';
81+
const customerTokenLifetime = 3600;
8182
const signInMock = {
8283
request: {
8384
query: defaultOperations.signInMutation,
8485
variables: signInVariables
8586
},
8687
result: {
87-
data: { generateCustomerToken: { token: authToken } }
88+
data: {
89+
generateCustomerToken: {
90+
token: authToken,
91+
customer_token_lifetime: customerTokenLifetime
92+
}
93+
}
8894
}
8995
};
9096

@@ -202,7 +208,7 @@ describe('handle submit event', () => {
202208
await result.current.handleSubmit(formValues);
203209
});
204210

205-
expect(mockSetToken).toHaveBeenCalledWith('auth-token-123');
211+
expect(mockSetToken).toHaveBeenCalledWith('auth-token-123', 3600);
206212
expect(createAccount).toHaveBeenCalled();
207213
expect(mockRemoveCart).toHaveBeenCalled();
208214
expect(mockCreateCart).toHaveBeenCalledWith({

packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const SIGN_IN = gql`
4444
mutation SignInAfterCheckout($email: String!, $password: String!) {
4545
generateCustomerToken(email: $email, password: $password) {
4646
token
47+
customer_token_lifetime
4748
}
4849
}
4950
`;

packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ export const useCreateAccount = props => {
117117
...recaptchaDataForSignIn
118118
});
119119
const token = signInResponse.data.generateCustomerToken.token;
120-
await setToken(token);
120+
const customerTokenLifetime =
121+
signInResponse.data.generateCustomerToken
122+
.customer_token_lifetime;
123+
124+
await (customerTokenLifetime
125+
? setToken(token, customerTokenLifetime)
126+
: setToken(token));
121127

122128
// Clear guest cart from redux.
123129
await removeCart();

packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ const signInMutationFn = jest.fn().mockReturnValue([
102102
jest.fn().mockReturnValue({
103103
data: {
104104
generateCustomerToken: {
105-
token: 'customer token'
105+
token: 'customer token',
106+
customer_token_lifetime: 3600
106107
}
107108
}
108109
}),
@@ -272,10 +273,12 @@ describe('handleSubmit', () => {
272273

273274
test('should signin after account creation', async () => {
274275
const token = 'customertoken';
276+
const customer_token_lifetime = 3600;
275277
const signIn = jest.fn().mockReturnValue({
276278
data: {
277279
generateCustomerToken: {
278-
token
280+
token,
281+
customer_token_lifetime
279282
}
280283
}
281284
});
@@ -298,7 +301,7 @@ describe('handleSubmit', () => {
298301
password: defaultFormValues.password
299302
}
300303
});
301-
expect(setToken).toHaveBeenCalledWith(token);
304+
expect(setToken).toHaveBeenCalledWith(token, customer_token_lifetime);
302305
});
303306

304307
test('should clear cart data from cache', async () => {

packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const SIGN_IN = gql`
4545
mutation SignInAfterCreate($email: String!, $password: String!) {
4646
generateCustomerToken(email: $email, password: $password) {
4747
token
48+
customer_token_lifetime
4849
}
4950
}
5051
`;

packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ export const useCreateAccount = props => {
136136
...recaptchaDataForSignIn
137137
});
138138
const token = signInResponse.data.generateCustomerToken.token;
139-
await setToken(token);
140-
139+
const customerTokenLifetime =
140+
signInResponse.data.generateCustomerToken
141+
.customer_token_lifetime;
142+
await (customerTokenLifetime
143+
? setToken(token, customerTokenLifetime)
144+
: setToken(token));
141145
// Clear all cart/customer data from cache and redux.
142146
await apolloClient.clearCacheData(apolloClient, 'cart');
143147
await apolloClient.clearCacheData(apolloClient, 'customer');

packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,20 @@ const signInVariables = {
6161
password: 'slurm is the best'
6262
};
6363
const authToken = 'auth-token-123';
64+
const customerTokenLifetime = 3600;
6465

6566
const signInMock = {
6667
request: {
6768
query: defaultOperations.signInMutation,
6869
variables: signInVariables
6970
},
7071
result: {
71-
data: { generateCustomerToken: { token: authToken } }
72+
data: {
73+
generateCustomerToken: {
74+
token: authToken,
75+
customer_token_lifetime: customerTokenLifetime
76+
}
77+
}
7278
}
7379
};
7480

@@ -156,7 +162,7 @@ test('handleSubmit triggers waterfall of operations and actions', async () => {
156162
await act(() => result.current.handleSubmit(signInVariables));
157163

158164
expect(result.current.isBusy).toBe(true);
159-
expect(setToken).toHaveBeenCalledWith(authToken);
165+
expect(setToken).toHaveBeenCalledWith(authToken, customerTokenLifetime);
160166
expect(getCartDetails).toHaveBeenCalled();
161167
expect(getUserDetails).toHaveBeenCalled();
162168

packages/peregrine/lib/talons/SignIn/signIn.gql.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const SIGN_IN = gql`
1717
mutation SignIn($email: String!, $password: String!) {
1818
generateCustomerToken(email: $email, password: $password) {
1919
token
20+
customer_token_lifetime
2021
}
2122
}
2223
`;

packages/peregrine/lib/talons/SignIn/useSignIn.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ export const useSignIn = props => {
8686
});
8787

8888
const token = signInResponse.data.generateCustomerToken.token;
89-
await setToken(token);
89+
const customerTokenLifetime =
90+
signInResponse.data.generateCustomerToken
91+
.customer_token_lifetime;
92+
93+
await (customerTokenLifetime
94+
? setToken(token, customerTokenLifetime)
95+
: setToken(token));
9096

9197
// Clear all cart/customer data from cache and redux.
9298
await apolloClient.clearCacheData(apolloClient, 'cart');

0 commit comments

Comments
 (0)