Skip to content
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

Fixing netlifyIdentity login bug #9

Closed
wants to merge 5 commits into from
Closed

Fixing netlifyIdentity login bug #9

wants to merge 5 commits into from

Conversation

luczaki114
Copy link
Contributor

@luczaki114 luczaki114 commented Nov 20, 2017

The problem:
Sometimes the NetlifyIdentity script did not finish loading before the below script executed.

<script>
  if (window.netlifyIdentity) {
    window.netlifyIdentity.on("init", user => {
      if (!user) {
        window.netlifyIdentity.on("login", () => {
          document.location.href = "/admin/";
        });
      }
    });
  }
</script>

This script is necessary on the home page since netlifyIdentity's auth process involves sending a Json Web Token to the home page for verification, at which point you are logged in, and sent back to the admin page.

The solution:
I added a react-load-script dependency and used it to call the netlifyIdentity script and created an onLoad handler where I placed the script that needs to execute.

I also added in a manual netlifyIdentity.init() call since netlifyIdentity.js only adds itself to the window, but does not initialize.

…-netlify-cms

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
@luczaki114
Copy link
Contributor Author

Actually, dont merge this. I'll create a clean copy so its just one commit.

@luczaki114 luczaki114 closed this Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant