JWT身份验证尝试返回404

时间:2019-03-04 17:03:24

标签: ruby-on-rails ruby reactjs

您好,我正在尝试使用react前端从Rails后端应用程序获取身份验证令牌。我收到404错误,当我使用邮递员获取令牌时,同样的事情正在起作用

反应码

fetch('http://localhost:3000/authenticate', {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
    },
    body: {"email":"abc@mail.com","password":"password"}
})

轨道代码

#app/controllers/application_controller.rb
class ApplicationController < ActionController::API




  before_action :authenticate_request
     attr_reader :current_user

  before_action :set_headers
     private def authenticate_request
       @current_user = AuthorizeApiRequest.call(request.headers).result
       render json: { error: 'Not Authorized' }, status: 401 unless @current_user
     end

     private def set_headers
      headers['Access-Control-Allow-Origin'] = '*'
      headers['Access-Control-Expose-Headers'] = 'ETag'
      headers['Access-Control-Allow-Methods'] = 'GET, POST, PATCH, PUT, DELETE, OPTIONS, HEAD'
      headers['Access-Control-Allow-Headers'] = '*,x-requested-with,Authorization,Content-Type,If-Modified-Since,If-None-Match'
      headers['Access-Control-Max-Age'] = '86400'
    end
   end

请帮助我解决此问题,我俩都是新手。

邮递员屏幕截图 Postman screenshot

0 个答案:

没有答案