Cannot get invited users into my CMS

I have a few problems here. My site is written in Gatsby/React and I use the Netlify CMS. Everything works fine however I now need to add a user to my admin. I have enabled Identity and setup the invite users and emailed myself. The emailer works and directs to my homepage however it doesn’t throw the modal, so I set up a Login button and allowed Open Registration just to test it. It allows me to sign up, and then I can login and log out on the main page of my site no problem (there is nothing to log in or out of however, I only want CMS functionality) . So I have my basic admin index.html file:

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
  <title>Content Manager</title>
</head>

<body>
  <!-- Include the script that builds the page and powers Netlify CMS -->
  <script src="https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js"></script>
</body>

my config.yml

`backend:
  name: github
  repo: csmaller/blog

media_library:
  name: uploadcare
  config:
    publicKey: xxxxx
media_folder: content/assets
public_folder: ../assets

collections:
  - name: blog
    label: Blog
    folder: content/blog
    create: true
    fields:
      - {
          name: isNews,
          label: Is News,
          widget: 'boolean',
          default: false,
          required: false,
        }
      - { name: path, label: Path }
      - { name: date, label: Date, widget: date }
      - { name: title, label: Title }
      - { name: description, label: Description, required: false }
      - { name: body, label: Body, widget: markdown }`

and my cms.js

import CMS from 'netlify-cms-app';
import uploadcare from 'netlify-cms-media-library-uploadcare';

CMS.registerPreviewStyle('/styles.css');
CMS.registerMediaLibrary(uploadcare);

when I access my admin page it goes directly to my blog posts and logs me in but when i open an incognito window and clear my cache my dummy email account that I invited cannot log in.

here is my netlifyAuth.js I included on my index page and tested out with a modal and it all “works” (meaning it logs me in and out)

import netlifyIdentity from 'netlify-identity-widget';

const netlifyAuth = {
  isAuthenticated: false,
  user: null,
  initialize(callback) {
    window.netlifyIdentity = netlifyIdentity;
    netlifyIdentity.on('init', (user) => {
      callback(user);
    });
    netlifyIdentity.init();
  },
  authenticate(callback) {
    this.isAuthenticated = true;
    netlifyIdentity.open();
    netlifyIdentity.on('login', (user) => {
      this.user = user;
      callback(user);
      netlifyIdentity.closeModal();
    });
  },
  closeModal() {
    netlifyIdentity.close();
  },
  signout(callback) {
    this.isAuthenticated = false;
    netlifyIdentity.logout();
    netlifyIdentity.on('logout', () => {
      this.user = null;
      callback();
    });
  },
};

export default netlifyAuth;
type or paste code here

Did you add this script:

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

as explained in the docs: Add to Your Site | Netlify CMS | Open-Source Content Management System

hi, I am using Gatsby and React. there really isn’t an “index” page in gatsby so I put that code in a useEffect
on the index.tsx landing page.

`useEffect(() => {
    if (typeof "window" !== "undefined") {
      ReactGA.pageview(window.location.pathname + window.location.search);

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


    }
  }, [])`


it still doesn’t work or redirect. It doesn’t see window.netlifyIdenty and doesn’t get into the init functionality.

Yeah you won’t have access to window.netlifyIdentity since you’re using a bundler, but maybe you can import Identity widget in this component too and use that?

thanks for your help.
So I feel like Im getting a little closer but…
two things: you invite someone from the App dashboard in netlify they dont have a password, so I reset password and then it redirects back to my home page, I guess I have to write something that allows password setting? I also opened up reg so you can sign right up and use that login, which I did. So now when I login from the home page it redirects to admin but then asks me to login with Github and doesn’t log me in directly since my dummy email account I am testing with does not use github and I think you need to be logging into the github account that the account is linked to anyways. So, now I am just at my wits end.

    if (typeof "window" !== "undefined") {
      ReactGA.pageview(window.location.pathname + window.location.search);
      netlifyAuth.initialize(() => {
        if (window.netlifyIdentity) {
          if (!user) {
            window.netlifyIdentity.on("login", () => {
              document.location.href = "/admin/";
            });
          }
        };
//need this to be able to click the Login button
        netlifyAuth.closeModal();
      }
      );
    }
  }, [])


here is my initialize function in netlifyAuth.js

initialize(callback) {
    window.netlifyIdentity = netlifyIdentity;
    netlifyIdentity.on('init', (user) => {
      callback(user);
    });
    netlifyIdentity.init();
  },

OK, so instead of all of the mucking about with the plugin I copied html.js and inserted directly into the HTML code and the invite works and the reset password works. but when it redirects to admin it still stops the user and say “login with Github”.

This might help:

Hi Tom, thanks for your help
that is not the problem however. I enabled Netlify Identity for admin login but now I go to my admin and get “Git Gateway Error: Please ask your site administrator to reissue the Git Gateway token.” so. I went and reissued the git token in Identity->Services->git Gateway. also I did another deploy and still get this error. I also tried changing my config file in admin . I have googled that I need to name the branch “main” so I tried “master” and now “main”

backend:
  name: git-gateway
  repo: csmaller/blog
  branch: main

Also, I have cleared all my cookies and refreshed and that doesnt throw that alert until I actually go through the login (thinking I got it) and then it just refreshes the page and shows that error again. grr

and in the console I get this error :

{message: "Bad credentials", documentation_url: "https://docs.github.com/rest"}
documentation_url: "https://docs.github.com/rest"
message: "Bad credentials"

Hi there, @coreysmaller :wave:

Sorry for the delay here. Are you still experiencing errors? If so, can you please share any interim steps you have taken to work on this?

Hi hillary
yes as it turns out I renamed the github repo and forgot to change it in my admin config. once I did that, reset my Identity settings and API key, nuked my users and cleared cookies it worked! Thank you

1 Like

Thanks so much for coming back and sharing your solution! Glad everything is working for you now. :netliconfetti:

1 Like