-
Notifications
You must be signed in to change notification settings - Fork 116
fix: expired user token #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4954bfb
fix(theme): disabled checkbox on login-modal
KevinGorjan aa4efdc
feat(theme): log customer out when customer-token is expired
KevinGorjan ea1f868
feat: added token expired notification, clear cart and customer token…
f99c14c
feat: logged out notification
6904170
refactor: removed console log
ec2e4da
refactor: added improvements for token-expired plugin, added unit tests
39f1294
refactor: changed log out notification message
9925977
test: fixed token-expired plugin test
8707b43
Merge branch 'develop' into bug/m2-24-expired-user-token
7323060
Merge branch 'develop' into bug/m2-24-expired-user-token
31b83ea
test: added cookies mock to test-utils
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,6 +226,7 @@ export default { | |
| }, | ||
| }, | ||
| plugins: [ | ||
| '~/plugins/token-expired', | ||
| '~/plugins/i18n', | ||
| ], | ||
| router: { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import tokenExpiredPlugin from '../token-expired'; | ||
| import cookieNames from '~/enums/cookieNameEnum'; | ||
|
|
||
| const callbackResponse = { | ||
| data: { | ||
| message: 'The current customer isn\'t authorized.', | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| const appMock = { | ||
| $vsf: { | ||
| $magento: { | ||
| client: { | ||
| interceptors: { | ||
| response: { | ||
| use: (callback) => { | ||
| callback(callbackResponse); | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| $cookies: { | ||
| remove: jest.fn(), | ||
| set: jest.fn(), | ||
| }, | ||
| localePath: (t) => t, | ||
| i18n: { | ||
| t: (t) => t, | ||
| }, | ||
| }; | ||
|
|
||
| const redirectMock = jest.fn(); | ||
|
|
||
| describe('Token Expired plugin', () => { | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it('should work only when the current customer is not authorized', async () => { | ||
| // eslint-disable-next-line @typescript-eslint/await-thenable | ||
| await tokenExpiredPlugin({ app: appMock, redirect: redirectMock }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/'); | ||
| }); | ||
|
|
||
| it('should set message cookie', async () => { | ||
| // eslint-disable-next-line @typescript-eslint/await-thenable | ||
| await tokenExpiredPlugin({ app: appMock, redirect: redirectMock }); | ||
|
|
||
| const messageMock = { | ||
| icon: null, | ||
| message: 'You are not authorized, please log in.', | ||
| persist: true, | ||
| title: null, | ||
| type: 'warning', | ||
| }; | ||
|
|
||
| expect(appMock.$cookies.set).toHaveBeenCalledWith('vsf-message', messageMock); | ||
| }); | ||
|
|
||
| it('should clear customer token and clear cart id', async () => { | ||
| // eslint-disable-next-line @typescript-eslint/await-thenable | ||
| await tokenExpiredPlugin({ app: appMock, redirect: redirectMock }); | ||
|
|
||
| expect(appMock.$cookies.remove).toHaveBeenCalledTimes(2); | ||
| expect(appMock.$cookies.remove).toHaveBeenCalledWith(cookieNames.customerCookieName); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import cookieNames from '~/enums/cookieNameEnum'; | ||
|
|
||
| export default ({ app, redirect }) => { | ||
Frodigo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let once = true; | ||
|
|
||
|
|
||
| app.$vsf.$magento.client.interceptors.response.use(async (r) => { | ||
|
|
||
| if (r.data.message === 'The current customer isn\'t authorized.' && once) { | ||
| once = false; | ||
| app.$cookies.remove(cookieNames.customerCookieName); | ||
| app.$cookies.remove(cookieNames.cartCookieName); | ||
|
|
||
| await app.$cookies.set(cookieNames.messageCookieName, { | ||
| message: app.i18n.t('You are not authorized, please log in.'), | ||
| type: 'warning', | ||
| icon: null, | ||
| persist: true, | ||
| title: null, | ||
| }); | ||
|
|
||
| redirect(app.localePath('/')); | ||
| } | ||
|
|
||
| return r; | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.