服务器端的Firebase电子邮件验证

问题描述:

我有一个指向Firebase中默认电子邮件验证功能的链接.从浏览器使用此链接可以正常工作,但是在服务器端使用以下代码使用时,该链接将失败:

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);
  }

当我复制服务器端使用的URL时,完全相同的URL在浏览器中有效,但在服务器端却失败.将不胜感激什么是问题.

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.

这是因为对该URL的调用不会返回响应,您可以检查该响应,例如REST API端点的响应,例如 response.data.success .

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.

您将会在此处看到,该URL应该用于打开网页,您将在其中进行以下操作:

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

  1. 获取作为QueryString参数传递的值(例如 mode oobCode )
  2. 从网页中调用Firebase JavaScript SDK的某些方法,例如您也许可以在服务器上模仿此操作,但我从未尝试过.

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