I am using signInWithRedirect from firebase/auth package. Starting from June 2024 we need to implement one of the 5 options for it to work, when the app is not hosted on firebase. My app is hosted on Netlify. I was trying to go with option 3 – proxy request to firebaseapp.com.
I have used Netlify edge functions to implement proxy:
export default async (request, context) => {
const url = new URL(request.url);
if (url.pathname.startsWith("/__/auth/")) {
const newUrl = new URL(request.url);
newUrl.hostname = "my-firebase-app.firebaseapp.com";
const proxyRequest = new Request(newUrl.toString(), request);
return fetch(proxyRequest);
}
return context.next();
};
export const config = { path: "/__/auth/*" };
I have also updated my firebase config with changed authDomain:
authDomain: my-netlify-app.com
When I call signInWithRedirect I do get redirected to some google page, but it gives this error:
You can’t sign in because this app sent an invalid request. You can
try again later, or contact the developer about this issue. Learn more
about this error If you are a developer of this app, see error
details. Error 400: redirect_uri_mismatch
I have clicked the links and read the docs, I also went to my Credentials page of Google console, and I definitely added:
OAuth 2.0 Client IDs
Authorized JavaScript origins: https://my-netlify-app.com
Authorized redirect URIs: https://my-netlify-app.com/__/auth/handler
Still I get this redirect_uri_mismatch
error:
Request details: redirect_uri=https://my-netlify-app.com/__/auth/handler flowName=GeneralOAuthFlow
I meanwhile intend to use signInWithPopup which I don’t really like but it works if I do not change authDomain.
2
Answers
under authorised URI I added:
and for javascript origins I also added:
That worked for me
can you read the readme of this repo where I explain a little about the configuration to solve