Transferring firebase authentication session

Hi all, I have a webapp that uses firebase authentication. I want to enable the users to use NetlifyCMS without needing to enter credentials again as they already did to login to their account. Is it possible to some how transfer the session to NetlifyCMS? thanks.

Hi @pirzol,

It’s possible, but I’d say using Identity would end up being easier. But if you want to do it and considering Firebase Auth supports JWT, you can do it like this:

Is short, you might have to configure a custom Git gateway.

Thank you, when you say that using identity is easier, do you mean that I will have to change my app authentication to netlify identity?

No. That would add a lot more changes to the code. I simply meant, you can keep your Firebase Auth users and Identity users different. Basically, ask them to re-sign-up on Netlify Identity. Not very user-friendly, but that’s the only option to save development time.

1 Like

Hi @pirzol, to add to the great suggestion about a custom Git Gateway by @hrishikesh, the underlying issue is that the CMS needs to access a GitHub/GitLab/Bitbucket repo.

Is your firebase authentication configured to use GitHub? If so you might be able to add the repo scope as described here, and set the received token in local storage to be used by the CMS.
You’ll need to set a local storage key named netlify-cms-user with the following value:

{
  backendName: 'github',
  login: '<login>',
  id: '<id>',
  avatar_url: '<avatar_url>',
  name: '<name>',
  token: '<token>'
}

You should get all the above values from the GitHub user object received after authenticating.
If you set the correct values before loading the CMS, it will assume the user is authenticated and load correctly.

Another possible option, if your users are not using Firebase + GitHub to authenticate, is to write a custom CMS backend (see here for example) that sends the Firebase token to a custom service provided by you and receives a valid token to access the repo (this is very similar to a custom Git Gateway).

1 Like