Authenticating a Spree User (Spree Auth Devise) using a javascript request

Authenticating a Spree User (Spree Auth Devise) using a javascript request

Just for future reference in Spree you can use the following code in spite of authenticate an existent user created in a Spree Store

var server = 'http://localhost:3000';
var userAuthUrl = server + '/login.js';
var data = {spree_user: {email: "spree@example.com", password: "spree123"}}
$.ajax({
  type: "POST",
  data: data,
  url: userAuthUrl,
  success: function(data, textStatus, jqXHR) {
    console.log(data);
    console.log(textStatus);  
    console.log(jqXHR);
  }
});


The before request will return to you a successful response if the user data is valid, the response will include something like:

{"user":{"id":1,"email":"spree@example.com","persistence_token":null,"perishable_token":null,"last_request_at":null,"login":"spree@example.com","ship_address_id":null,"bill_address_id":null,"authentication_token":null,"created_at":"2014-09-04T17:59:59.693Z","updated_at":"2014-09-05T14:51:19.181Z","spree_api_key":"5e8781aa6203b16956b67608e1122d57005dd89e9ac69a6b32"},"ship_address":null,"bill_address":null}
No Comments

Post A Comment