Skip to content

Commit

Permalink
Merge pull request #12 from afosto/Fix/session-storage-window-check
Browse files Browse the repository at this point in the history
Fix/session-storage-window-check
  • Loading branch information
Rapid0o authored Mar 29, 2022
2 parents 60b952b + 51f9219 commit 2105d40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@afosto/instant-search-client",
"version": "1.0.4",
"version": "1.0.5",
"private": false,
"description": "The Afosto InstantSearch client",
"main": "./dist/afosto-instant-search.min.js",
Expand Down
7 changes: 4 additions & 3 deletions src/utils/getSessionID.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { v4 as uuid } from 'uuid';
import { SESSION_KEY } from '../constants';

const getSessionID = () => {
const hasSessionStorage = !!window.sessionStorage;
const isBrowser = typeof window !== 'undefined';
const hasSessionStorage = isBrowser && !!window.sessionStorage;

if (!hasSessionStorage) {
return uuid();
}

let sessionID = sessionStorage.getItem(SESSION_KEY);
let sessionID = window.sessionStorage.getItem(SESSION_KEY);

if (!sessionID) {
sessionID = uuid();
sessionStorage.setItem(SESSION_KEY, sessionID);
window.sessionStorage.setItem(SESSION_KEY, sessionID);
}

return sessionID;
Expand Down

0 comments on commit 2105d40

Please sign in to comment.