私はちょっと立ち往生して解決策を見つけることができませんでした。フロントエンドにdeviseを、apiにdevise_token_authを使用するレールサイトがあります。フロントエンドは、サーバー側のレンダリングされたページとAPIコールの組み合わせを使用して、ユーザーにデータを表示します。私は純粋な角度ログインを使用する場合 ログインフォームはeventally(ushally 2-3提出を)動作します:Devise、devise_token_auth、およびng-token-authの認証に関する問題
%div{'ng-controller'=>'logInCtrl'}
%h2 Log In
%div{:layout=>'column'}
%div{:flex=>20}
%div{:flex=>60, :layout=>'column'}
= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
%div{:layout=>'column'}
%md-input-container
=f.label :login
%input{'ng-model'=>'loginForm.login', :autofocus => 'true'}
%md-input-container
= f.label :password
%input{:type=>'password', 'ng-model'=>'loginForm.password', :autocomplete => 'off'}
%md-input-container
%md-button.md-raised.md-primary{'ng-click'=>'submitMe()'}
-#{:type=>'submit'}
%md-icon.mdi.mdi-account-key
Log In
:coffee
myApp.controller 'logInCtrl', ($scope, $resource, $http, $mdDialog, $auth) ->
$scope.submitMe =() ->
$auth.submitLogin($scope.loginForm).then((resp)->
location.replace('/users/sign_in')
)
私は、正しい情報がサーバーによってレンダリングされた標準のPOSTメソッドを使用しますが、トークンセットが存在しない場合にはng-token-auth
# POST /resource/sign_in
def create
super do |user|
newAuth = user.create_new_auth_token
response.headers.merge!(newAuth)
end
end
を私はこのアプローチを持っている問題はそれがなかったので、NG-トークン認証は、ヘッダからトークンを拾うことがないということです:私は使用してセッション#上で手動でトークンヘッダを作成して生成して送信することができます要求を行う。私は手でトークンヘッダーを設定する方法を探しました。
- 私は最終的にはoauthソリューションに移行していないので、私が使用している回避策はすべて移植する必要があります。 - サーバー側のレンダリングでは、デザイン要素の処理だけでなく、機能のオンとオフを切り替える必要があります。また、current_userの要素を使用して、ユーザーの場所に基づいてテーブル名のサブセットを設定します。