首页 > 解决方案 > 使用电子邮件从获取请求中获取数据

问题描述

我正在尝试通过电子邮件获取用户详细信息,为此我使用了以下方法,但我收到 500 内部服务器错误

  getUser = (email) => {
    console.log("reached");
    const PATH = `${this.BASE_URL}/getUser`;
    return this.http.get(PATH, email).pipe(
      map((res: any) => res),
      catchError((error: any) =>
        observableThrowError(error.error || "Server error")
      )
    );
  };

我在 getUser 路线上的获取请求

  public static async getUser(req, res, next) {
    try {
      const email = req.body.email;
      console.log("email", email);
      const user = await User.findOne({ email: email });
      res.json({
        token: jwt.encode(getJwtPayload(user), UserRoutes.JWT_SECRET),
        user,
      });
    } catch (error) {
      next(error);
    }
  }

标签: angularmongoose

解决方案


推荐阅读