Programatically identify a user


I recently installed the netlify cms and I really love it. I want to give access to my users to the edit functionality but I want to log them in with slack.

The solution I came up with is to return the identify username and password from a cloud function once the user logs in with slack. But for that I need to programmatically log them in in the CMS. Is there a way to do so?


On page load, you can:

document.querySelector('input[type="email"]').value = username
document.querySelector('input[type="password"]').value = password

This will automatically fill the values in the form and submit it, which would log the user in.

1 Like

Thank you for the answer. But this is not working for me because it can not find the elements.
I think that it is somehow connected with it being an iframe, because after I manually inspect then it works

Oh yeah, forgot about iframe. You can do it like:
const iframe = document.querySelector('iframe').contentWindow
iframe.document.querySelector('input[type="email"]').value = username
iframe.document.querySelector('input[type="password"]').value = password

In this scenario, you’d have to run without an option as till the pop-up doesn’t open, the iframe won’t be added to the page and thus, the rest of the code won’t work.

1 Like

Cool. Now I am able to find the iframe and add the values to the input boxes but when I hit submit nothing seems to happen. No request is made, no message, nothing… Were yo able to make it work?

Looks like I should have tried it before posting, but I “assumed” it would work.

Anyways, this would work:

netlifyIdentity.gotrue.login('', 'foo')

Notes on how to login:


This worked!! Thank you so much!

1 Like