1

I have a link to default email verification function in Firebase. Using this link from the browser works fine, however it fails when being used from server side with the following code:

  try {
    const url = `https://example.com/__/auth/action?mode=verifyEmail&oobCode=${oobCode}&apiKey=${apiKey}&lang=en`;
 
    const response = await axios.get(url);
    
    if (response.data.success) {
      return next();
    } else {
        return next(new ErrorResponse("Failed email verification", FORBIDDEN));
    }
  } catch (error) {
    return sendFailedWithErr(res, error.message);
  }

When I am copying the URL used in the server side the exact same URL works from the browser, but fails on the server side. Would appreciate any idea what is the problem.

1 Answers1

1

This is because a call to this URL is not going to return a response that you can check like the response of a REST API endpoint with, e.g. response.data.success.

As you will see here, this URL is supposed to be used to open a web page in which you will:

  1. Get the values passed as QueryString parameters (e.g. mode or oobCode)
  2. Call, from the web page some methods of the Firebase JavaScript SDK, like applyActionCode() in the case of email verification.

You may be able to mimic this action from a server, but I've never tried.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • 1
    Thank you Renaud Tarnec. I took your answer from https://stackoverflow.com/questions/67091834/customized-email-verification-success-page-using-firebase – Raya Levinson Apr 26 '21 at 10:51