Skip to content

Commit

Permalink
fix(gatsby-plugin-netlify-cms): ensure login listener is added after …
Browse files Browse the repository at this point in the history
…logout
  • Loading branch information
Undistraction authored and pieh committed Sep 24, 2018
1 parent efe95a4 commit 9b1a2e7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/gatsby-plugin-netlify-cms/src/cms-identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
import netlifyIdentityWidget from "netlify-identity-widget"

window.netlifyIdentity = netlifyIdentityWidget

const addLoginListener = () =>
netlifyIdentityWidget.on(`login`, () => {
document.location.href = `${__PATH_PREFIX__}/${CMS_PUBLIC_PATH}/`
})

netlifyIdentityWidget.on(`init`, user => {
if (!user) {
netlifyIdentityWidget.on(`login`, () => {
document.location.href = `${__PATH_PREFIX__}/${CMS_PUBLIC_PATH}/`
addLoginListener()
} else {
netlifyIdentityWidget.on(`logout`, () => {
addLoginListener()
})
}
})

netlifyIdentityWidget.init()

0 comments on commit 9b1a2e7

Please sign in to comment.