![](/img/trans.png)
[英]how can i wait for firebase to check the user is valid before sending a POST request with reactjs?
[英]How can i check a JWT token is valid using an async function route with nodejs?
我按照下面的指南来验证只有注册用户才能向我的后端 nodejs 服务器发送请求,我的前端正在发送带有授权 header 的请求,其中包含一个令牌并且该部分运行良好。 nodejs 后端应该在发送响应之前检查令牌是否有效: https://www.tonyvu.co/posts/jwt-authentication-node-js
该示例显示我应该在我的路线中添加如下所示的“AuthenticateJWT”:
app.post(“/api/token”, authenticateJWT, (req, res) => {
...
});
但是我的路线是异步 function ,我找不到正确的语法来添加它。 我的代码如下:
router.post('/account/user_load_balance', async function (req, res) {
...
});
我尝试了以下方法:
router.post('/account/user_load_balance', async function, authenticateJWT (req, res) try {
...
});
但这给了我一个错误:
Unexpected token ','
什么是正确的语法?
可以翻示例代码:
app.post(“/api/token”, authenticateJWT, (req, res) => {
...
});
进入异步 function 示例,只需将async
关键字添加到已经存在的 function 中:
app.post(“/api/token”, authenticateJWT, async (req, res) => {
...
});
假设您有一个已经可以使用的authenticateJWT
,那么将其调整为您自己的使用应该是微不足道的。
也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.