This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove usage session ID cookie and use ephemeral Vuex data
- Loading branch information
1 parent
e603ec3
commit 8211525
Showing
6 changed files
with
51 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import SessionId from '~/utils/session-id' | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
/** | ||
* @typedef UserState | ||
* @property {string | undefined} usageSessionId | ||
*/ | ||
|
||
/** | ||
* @returns {UserState} | ||
*/ | ||
export const state = () => ({ | ||
abSessionId: SessionId('abSessionId', true), | ||
usageSessionId: SessionId('usageSessionId'), | ||
/** | ||
* Default to `undefined` on the client and let client side | ||
* SSR state hydration pull the SSR generated ID into the client. | ||
* This way we avoid generating any spurious IDs on the client. | ||
*/ | ||
usageSessionId: process.server ? uuidv4() : undefined, | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains 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,28 @@ | ||
import * as user from '~/store/user' | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
jest.mock('uuid', () => ({ v4: jest.fn() })) | ||
|
||
describe('user store', () => { | ||
beforeEach(() => { | ||
process.server = false | ||
process.client = false | ||
}) | ||
|
||
afterAll(() => { | ||
// avoid polluting other tests that might be affected by these flags | ||
delete process.server | ||
delete process.client | ||
}) | ||
|
||
it('should generate a new usageSessionId when on server', () => { | ||
uuidv4.mockReturnValue('abcd-1234') | ||
process.server = true | ||
expect(user.state().usageSessionId).toEqual('abcd-1234') | ||
}) | ||
|
||
it('should not generate a new usageSessionId when on client', () => { | ||
process.client = true | ||
expect(user.state().usageSessionId).toBeUndefined() | ||
}) | ||
}) |
This file contains 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