Hello! This is a very common (and very frustrating) hurdle when developing in a cloud-based IDE, and I can absolutely help you solve it.
You are 100% correct in your thinking. The problem is that your Firebase Studio preview URL (e.g., https://my-app-123.cloudworkstation.dev) is not authorized to handle the Google Sign-In flow.
The good news is you were on the right track by adding it to Firebase. You just missed one crucial, separate step. To fix this, you need to add your Firebase Studio preview URL to two different places:
-
Firebase Console (which you’ve already done)
-
Google Cloud Console (this is the missing step)
The Google Sign-In popup involves three parties: your app, Firebase Auth, and Google itself. You’ve told Firebase to trust your app, but you also need to tell Google to trust your app.
Here is the complete step-by-step solution.
How to Authorize Your Firebase Studio Preview URL
Step 1: Find Your Exact Firebase Studio Preview URL
First, make sure your web app is running in the Firebase Studio preview panel. At the top of the panel, find the URL. It will look something like this:
https://12345-abcde-6789.cloudworkstation.dev
Copy this full URL (including the https://).
Step 2: Add to Firebase Auth “Authorized Domains”
This is the step you mentioned you already did, but let’s double-check.
-
Go to the Firebase Console (console.firebase.google.com).
-
Select your project.
-
Go to Authentication > Settings tab > Authorized Domains.
-
Click Add domain and paste in the domain part of your URL (e.g., 12345-abcde-6789.cloudworkstation.dev).
Step 3: Add to Google Cloud Console (The Missing Step)
This is the most important part. This authorizes your app with the underlying Google Identity services.
-
Go to the Google Cloud Console: https://console.cloud.google.com/
-
In the top project selector, make sure you have the same project selected that your Firebase project is using.
-
In the top search bar, type in “APIs & Services” and select it.
-
On the left menu, click on “Credentials”.
-
You will see a list of “OAuth 2.0 Client IDs”. Find the one with the type “Web client” that is used for your Firebase project (it may be named “Web client (auto created by Google Service)”).
-
Click the pencil icon (Edit) on the far right of that row.
-
You will see two lists. This is where you need to add your URL:
-
Authorized JavaScript origins: Click + ADD URI and paste in your full Firebase Studio preview URL (e.g., https://12345-abcde-6789.cloudworkstation.dev).
-
Authorized redirect URIs: Click + ADD URI and paste in your project’s special auth handler URL. You can find this in your Firebase console (under Authentication > Settings > Authorized Domains), or build it yourself. It looks like this:
https://YOUR-PROJECT-ID.firebaseapp.com/__/auth/handler
-
Click Save at the bottom of the page.
Wait 5 Minutes and Test
It can take 2-5 minutes for these changes to take effect across Google’s systems. After waiting a few minutes, go back to your Firebase Studio preview window, do a hard refresh (Ctrl+Shift+R or Cmd+Shift+R), and try the Google Sign-In button again.
Both the popup and redirect methods should now work perfectly.