Firebase Authentication with Workers

I want to use Firebase Authentication with workers. Below is the screenshot of the code that I'm running both locally (not as wrangler dev but using npx tsc and node) and on workers. When running locally on my machine the code works and it authenticates as expected. However, when I publish to cloudflare (npx wrangler publish) it throws the following error (shown in the screenshot). I was wondering if some has encountered this before or have some ideas on what could resolve this. Thank you!
No description
No description
3 Replies
Tin Cap
Tin Cap9mo ago
Looks like you're trying to use the Firebase client SDK. You should be using the Firebase Admin SDK in a worker.
FCReddit
FCReddit9mo ago
Interesting. Could you explain what is the difference between Client SDK and Admin SDK, and why Admin SDK would work? My logic (obviously flawed now) was that both are javascript libraries and should work on workers since I don't need the additional privilege that Admin SDK provides.
Tin Cap
Tin Cap9mo ago
The Client SDK is designed to be used in a webpage. You authenticate a single user with their credentials, they stay logged in, operations are checked against access rules, etc. The Admin SDK is designed for server user. You authenticate with a Google Cloud service account. You can query all data and there no access rules. You might be able to get the Client SDK working, but the Admin SDK is the right thing to use. The Cloudflare worker runtime environment isn't a browser and it's a little weird compared to normal javascript runtimes in other ways, so I wouldn't be shocked of the Client SDK had some type of issues running in Cloudflare workers.