gatsby-starter-decap-cms: Admin login not working?

I published the site (without any modification after creating) on Netlify (just by dropping the public folder), and enabled the Identity service (with gitlab provider). After logging in with Gitlab account I’m redirected to main site page (with OAuth access_token) but it didn’t redirect me back to admin interface. I had to add

<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>

in <head> and

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

before <body> end in main site index.html just as the documentation says. Shouldn’t you make gatsby add it automatically to public/index.html?

Nonetheless, admin interface now loads, but I fail to see any content that is already present on the site. But maybe it’s because the site was not created from Git.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

I seem to be having an issue with netlify identity as well.

When I go to /admin and login, I get redirected to the home page with a json token in the URL. I tried to login again, and keep returning to the home page with the token. It turns out that the

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

script is not actually running. An async callback does the trick, making sure the CDN netlify identity script runs before adding this on init function. netlifyIdentity also needs to be manually initialized with netlifyIdentity.init() after the on init eventhandler is passed. Once you have called the init() function with the token in the URL, you should get the logged in modal popup.

Side note: I got the CMS to work locally as well, by passing in the name “test-repo” in config.yml, which lets you use the browsers’ local storage to test whether your configuration is bug free. This will not let you actually publish to your github repo, so its really just for testing config.

Question: Austin, since you have both index.html and config.ym is static/admin, did you have to customize Gatsby’s webpack config to route to admin? it seems to only work in production. I took you boilerplate and added in the admin page as a widget. Any reason you didn’t go that route?