使用React Rails和设备JWT的基本身份验证:401

时间:2018-09-25 10:28:13

标签: ruby-on-rails reactjs

我正在尝试在reactrails

中实现基本身份验证

我正在使用宝石gem 'devise-jwt'

注册用户尝试登录后,我会得到Error: Request failed with status code 401

我的session_controller如下:

# frozen_string_literal: true

class Users::SessionsController < Devise::SessionsController
  respond_to :json

  private

  def respond_with(resource, _opts = {})
    render json: resource
  end

  def respond_to_on_destroy
    head :no_content
  end
end

react的请求是:

handleSubmit = () => {
    const data = this.state
    const headers = {
      'Content-Type': 'application/json',
    }
    axios
      .post(
        'http://192.168.1.21:3000/login',
        {
          user: data,
        },
        { headers },
      )
      .then(response => {
        console.log(response)
      })
      .catch(error => {
        console.log(error)
      })
  }

我正在连接到同一网络的另一台计算机上本地运行服务器。它在同一台机器上的POSTMAN应用程序中运行良好。但是,当我使用IP从另一台计算机发出请求时,出现上述错误。

我注意到的一个区别是-使用邮递员时,在Rails控制台中的请求密码显示为FILTERED,而来自前端的请求则为纯文本。

我在做什么错了?

0 个答案:

没有答案