Skip to content

Commit

Permalink
fix: Add a null check to the window 'storage' event listener (#1198)
Browse files Browse the repository at this point in the history
* Add a null check to the window 'storage' event listener

While testing in Cypress it's possible to receive a null value on Storage Events when 'clear' is called and will cause errors as seen in #1125.

* Update index.js

typo

* Update src/client/index.js

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* formatting

Co-authored-by: Balázs Orbán <info@balazsorban.com>
  • Loading branch information
dmmulroy and balazsorban44 committed Feb 1, 2021
1 parent 30c6d63 commit 65e4910
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (typeof window !== 'undefined') {
window.addEventListener('storage', async (event) => {
if (event.key === 'nextauth.message') {
const message = JSON.parse(event.newValue)
if (message.event && message.event === 'session' && message.data) {
if (message?.event === 'session' && message.data) {
// Ignore storage events fired from the same window that created them
if (__NEXTAUTH._clientId === message.clientId) {
return
Expand Down

0 comments on commit 65e4910

Please sign in to comment.