4

I am pretty newbie using Spree and I am just playing around with the 3.0 stable version.

I would like to log a user account into the store through API (or something like that) using the chrome app called "Advanced REST client", then visit the store and see the account logged there.

I couldn't find any reference for this kind of actions which involve users or accounts through API in https://guides.spreecommerce.com/api/. However, I noticed that if you make a POST request to localhost:3000/login sending the account details, you get the html code of the store which says that your were successfully logged.

After that I checked my browser cookies and the store session cookie was also created successfully. Finally, when I redirect the browser to the store (localhost:3000), the account is not logged in but the cookie still remains there.

I think is something related to the guest token generated by Spree, but I don't understand exactly why it doesn't work.

I would appreciate any help to clear this, also if you have any idea about how to get my goal it also would be appreciated.

Julian Rodriguez
  • 574
  • 6
  • 15

1 Answers1

0

In order to use a REST client, such as the Chrome app you mentioned, you have to authenticate against Spree's REST API. You need a spree api token to authenticate future request. Have a look at the Spree Api Auth Gem. It allows you to you receive an api token like this:

\curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"email":"camelmasa@gmail.com", "password":"camelmasa"}}' http://localhost:3000/api/users/sign_in

You can also create new user account using this gem. Since Spree is using devise underneath, you can also use devise directly to authenticate your user.

Nicholas
  • 5,770
  • 1
  • 20
  • 30
  • Hi! Thanks for the reply. I have tried the Spree Api Auth Gem but I got exactly the same result as before. Using this gem I got the id, spree_api_key, email, bill_address and the ship_addres as a json response. It actually creates the cookie, but the user is not logged into the store if I redirect the web browser to the store (in this case localhost:3000). I am trying to authenticate a user from another application using the same data. I thought it was as simple as an Api post request to Spree, then the cookie would make the rest of the work, but it wasn't. – Julian Rodriguez Jul 28 '15 at 16:24