Arvy Budiarto
Arvy Budiarto

Reputation: 13

How to use existing server token with emberjs simple auth

I'm currently implementing this library ember-simple-auth to manage authentication in the emberjs application (shopping cart) that I am currently building.

The difficulty that I encounter is that the library manages authentication rules after logging in very well but not before logging in.

So here is the scenario: The application must talk to the backend server to retrieve a session token for every user. This is necessary so that the user can save their items temporarily in the server side using session data. Something that you would expect for a shopping cart.

Then when the user is ready to move forward the application will then display the login screen and the user can authenticate themselves to checkout their items.

However, I can't seems to figure out yet how to do this using simple-auth. If I create a custom authenticator that just fetches token id from the server, it will mark the session as authenticated and will not ask for login on the authenticatedRoute.

In general what I'm trying to do are:

  1. Customer visit the website
  2. The application fetches session token from the server
  3. Customer clicks around and saves item into the shopping cart. The data is synced with the server using the session token
  4. Customer ready to checkout and navigates to checkout page
  5. The application intercepts the route and redirect the customer to login route, where the customer can login and resume checkout.

I hope the above information is clear enough. Any hints and help will be much appreciated. Thanks.

Upvotes: 1

Views: 400

Answers (1)

marcoow
marcoow

Reputation: 4062

I would probably only use Ember Simple Auth from the point on where the user actually logs in. Before that instead of using a session token to identify the basket, I'd probably explicitly create a basket on the server side (POST /basket) and then add to that via a REST interface (PUT /baskets/:id/items or so). That way you're not sharing state between the client and the server and have a clear interface. You also don't need to "abuse" Ember Simple Auth which probably only leads to other problems later on. When the user logs in then, you simply assign the previously created basket to that user and go on.

Upvotes: 1

Related Questions