我正在编写一个只允许用户同时从 1 个客户端登录的系统。
因此: 如果用户在 Phone 1 上登录(使用访问 token 1)并且用户抓取 Phone 2 再次登录(生成访问 token 2),我系统上的下一个 API 将被调用并返回错误代码。
现在这个错误代码将是 401。
一旦客户端检测到 401 响应,用户将被发送回登录页面,并会显示一条警报,告知用户该帐户已从另一台设备访问。
401 是用于此的正确错误代码吗?
最佳答案
401
错误代码表示未授权
。换句话说,如果用户尚未访问应用程序并使用无效凭据,将返回相同的错误。
我建议您使用 403 Forbidden
:
403 FORBIDDEN The server understood the request but refuses to authorize it.
或者409冲突
:
409 CONFLICT The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request.
关于http - 一次只能登录 1 响应代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45273490/