Search code examples
macosfirebase-authenticationelectronelectron-forge

How to implement Firebase Google Auth in an ElectronJs App that runs in background?


I am building an ElectronJs application which runs in background (in tray). I want to add Sign in with Google feature in the app using Firebase Auth. I tried searching but do not see any documentation around it. Few issues I faced:

  • I could get it working with the Renderer process but I want my Main process to hold User object as main process does API calls in background that require Auth token.
  • My app runs in background in tray, so it does not have an active window open at any time.

Is there a way I can implement auth code in main process and then use IPC to open the login window using renderer?


Solution

  • Here is the solution that worked for me

    1. Redirect user to a browser to login page. When login is done, trigger a deep link that opens the app. The deep link should contain the idToken other params.
    2. Parse the token from the url and use signinwithcredentials API of firebase auth. This takes the credentials object and performs the login.