2
나는 반응이있는 프론트 엔드와 레일 5 API 만 백 엔드를 가지고 있으며, 나는 simple_token_authentication 젬을 작동 시키려고 노력하고있다. 로그인하려고 시도 할 때이 오류가 발생합니다.레일 5 Api Only - Devise - react - simple_token_authentication
Started POST "https://stackoverflow.com/users/sign_in.json" for 100.38.166.199 at 2017-05-05 02:31:24 +0000
Processing by Users::SessionsController#create as JSON
Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "session"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}
Completed 401 Unauthorized in 2ms (ActiveRecord: 0.0ms)
CSRF와 관련이 있다고 의심됩니다. 나는 때때로 CSRF의 진위 오류 메시지가 있지만, 이상하게도 항상 여기
내 경로입니다하지 :Rails.application.routes.draw do
devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations'
}
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
scope module: 'api' do
namespace :v1 do
resources :properties
end
end
end
내 응용 프로그램 컨트롤러 (나는 또한 ActiveAdmin을 사용하고 있기 때문에 내가 가진)
class ApplicationController < ActionController::Base
respond_to :json
acts_as_token_authentication_handler_for User, fallback_to_devise: false
end
은 이것은 게시물 요청이 클라이언트 측에서 보이는 것입니다.
export function signinUser({ email, password }) {
return function(dispatch){
//submit email password to the server
axios.post(`${ROOT_URL}/users/sign_in.json`, { email, password })
.then(response => {
//if request is good, update state to indicate user is authenticated
dispatch({ type: AUTH_USER});
//-save the jwt token
localStorage.setItem('authentication_token', response.data.token);
//-redirect route somewhere
browserHistory.push('/test');
})
.catch(error => {
//if request is bad, show an error to the user
dispatch(authError(error));
})
};
}