Im a little stuck and i haven't been able to find a solution. I have a rails site that uses devise for the front end and devise_token_auth for the api. The front end uses a combination of server sided rendered pages and api calls to to display data to the user. The login form will eventally work (ushally 2-3 submits) if i use a pure angular login:
%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')
)
If i use a standard post method the correct information is rendered by the server but there is not token set for ng-token-auth. I can generate and send the token headers manually on session#create using:
# POST /resource/sign_in
def create
super do |user|
newAuth = user.create_new_auth_token
response.headers.merge!(newAuth)
end
end
The issue that i have with this approach is that ng-token-auth never picks up the token from the headers since it didn't make the request. I've looked for a way to manual set the token header with no luck.
-- As a side not i will eventually be moving to a oauth solution so whatever workaround i use will need to port to that. -- I should mention that the server side rendering take care of design elements as well as turning function on and off. I also use an element of current_user to set a sub-set of table names based on a users location.