Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 在基于React的应用程序中处理JWT令牌过期?_Rest_Reactjs_Authentication_Jwt - Fatal编程技术网

Rest 在基于React的应用程序中处理JWT令牌过期?

Rest 在基于React的应用程序中处理JWT令牌过期?,rest,reactjs,authentication,jwt,Rest,Reactjs,Authentication,Jwt,我们正在使用React和基于REST的服务器构建一个基于web的应用程序。出现的问题是,如何最好地管理以前经过身份验证的连接成为未经身份验证的连接,以及是否有任何React或React/Redux设计模式 以前的设计使用了会话,但由于REST服务器是无状态的,因此当前的REST服务器设计可能会考虑以下内容: POST /auth/authenticate --> Authenticate and provides a token DELETE /auth/token --&g

我们正在使用React和基于REST的服务器构建一个基于web的应用程序。出现的问题是,如何最好地管理以前经过身份验证的连接成为未经身份验证的连接,以及是否有任何React或React/Redux设计模式

以前的设计使用了会话,但由于REST服务器是无状态的,因此当前的REST服务器设计可能会考虑以下内容:

POST /auth/authenticate  --> Authenticate and provides a token
DELETE /auth/token       --> Invalidates the token, black-list token
PUT  /auth/token         --> Renews token, if still valid
GET  /auth/token         --> Indicates if token is still valid
在客户端,当前的草案设计是用我们自己的函数包装
fetch
函数,用于检查响应状态,然后调用客户端服务以使状态无效并重定向到登录页面,或者使用Redux执行同样的操作。我们还希望添加一个间隔计时器来检查我们拥有的令牌,然后在“exp”字段存在和过去时自动执行相同的操作

此时我们的功能是(此时不负责令牌的重新验证,以防止激活“会话”过期):

它将通过以下方式调用:

return handleFetchResponse( fetch(...) );

这是一种可接受的设计还是改进的方法?

您可以创建一个自定义thunk中间件,该中间件将有一个全局错误处理程序重定向到登录页面。您可以创建一个自定义thunk中间件,该中间件将有一个全局错误处理程序重定向到登录页面。
return handleFetchResponse( fetch(...) );