遵循此解决方案 https://stackoverflow.com/a/47761138/7818637我正在使用 devise_token_auth
gem 进行身份验证的 Rails 上设计忘记密码流 API。
<强>1。发送密码重置电子邮件的 POST 调用
网址:http://localhost:3000/client/auth/password
表单数据:{email: 'john@gmail.com', redirect_url: 'http://localhost:3000/client/auth/sign_in'}
<强>2。用于验证密码重置 token 的 GET 调用(在电子邮件中单击)
我在我的控制台上收到以下包含 redirect_url
和 reset_password_token
的 URL:
http://localhost:3000/client/auth/password/edit?config=default&redirect_url=http%3A%2F%2Flocalhost%3A3000%2Fclient%2Fauth%2Fsign_in&reset_password_token=ZBsx64Gk1VBraM3THZTn
当我调用此 URL 时,我收到以下错误:
Use POST /sign_in to sign in. GET is not supported.
我已经尝试过的:
关注问题here我发现我已经在我的 Controller 中使用 include DeviseTokenAuth::Concerns::SetUserByToken
。
控制台日志:
最佳答案
当用户单击您电子邮件中的 url 时,您会将他们重定向到 /password/edit 路径。在此操作中,您验证用户。如果一切顺利,用户将被重定向到 redirect_url,这是您的情况下的 sign_in 路径。
您应该更改电子邮件中的 redirect_url 并创建一个操作和一个 View ,用户将在其中被重定向。在这个新 View 中,您将拥有这样的字段,以便用户可以重置密码。确保新网址将使用“GET”。在提交表单时将用户重定向到登录路径,以便他/她可以使用新密码登录。
请阅读https://devise-token-auth.gitbook.io/devise-token-auth/usage/reset_password获取更多信息。
关于ruby-on-rails - devise_token_auth forget password API 显示 Use POST/sign_in to sign in. GET is not supported 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61815769/