Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to complete login with phonegap and devise (Rails)

I have a rails app that has devise gem installed (with auth_token setup). I'm not sure how to make my jquery mobile app ask for the token and store it (in a secure way). Thanks!

like image 812
montrealmike Avatar asked Sep 27 '11 19:09

montrealmike


1 Answers

i have a similar set up - rails 3 backend with devise as the authentication. i'm using standard jquery, though, on a full browser instead of a mobile, and i have my users log in through normal html forms.

in order to keep my users authenticated and be able to make backbone / jquery ajax calls back to my server, i had to add this to my rails.js file:

$.ajaxSetup({
  beforeSend: function(xhr) {
    xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
  }
}); 

once i put that in place, i didn't have to worry about authentication anymore.

hope that helps

like image 186
Derick Bailey Avatar answered Sep 30 '22 14:09

Derick Bailey