sparkartgroup-archive / sparkart.js

Easily interact with Sparkart's APIs via Javascript.
1 stars 0 forks source link

[#o8lF6STW] Check login status before sending API requests #56

Closed jameslovejoy closed 11 years ago

jameslovejoy commented 11 years ago

Branch: o8lF6STW-logged-in-endpoint

Services endpoint: https://github.com/SparkartGroupInc/sparkart-services/pull/227


To reduce the number of API requests from Sparkart.js, we're going to add new API endpoint. It will be very simple, just returning whether the current session is logged in. It won't query the database for the customer record or fanclub, or even check the API key. We want the endpoint to be a simple as possible, since it will be called on every request.

Widgets are now divided into two categories based on how they should behave when the user is not logged in:

Skip API request when not logged in

If the endpoint returns that the user is not logged in, then we can skip the API request and return a blank API response for certain widgets on the page:

These widgets will not make an API request but will still be rendered if the user is not logged in. What actually gets rendered depends on each widget template's markup and how it handles a response with no data.

Still make API request when not logged in

Certain other widgets do return data even for logged out users, so they will still need to make an API request:

However, the endpoints return the same data for all logged out users, and they always render the same for all logged out users. Therefore, these widgets can be cached via Hipster or some other mechanism.

Future widgets

By default, any new widgets will fall under the second scenario and still make an API request even when users are not logged in. To make a new widget skip its API request when users are not logged in, the widget must be added to the LOGGED_IN_WIDGETS array in Sparkart.js.

pushred commented 11 years ago

Markup should still render for widgets even if no requests are made. This will allow developers to display messaging instructing users to login. The Customer widget in particular is designed for that, offering a login button vs. logout.

djiang commented 11 years ago

This looks pretty good to me. @Fauntleroy would you mind taking a closer look?

jameslovejoy commented 11 years ago

I've updated the request to use JSONP for the account login check.

Timo614 commented 11 years ago

Awesome, looks all set.

:+1:

Timo614 commented 11 years ago

Let's wait to merge this until tomorrow -- Tim is going to take a look at it in the AM to make sure it's all set -- I have little experience with some of the core components of sparkart.js so just want to make sure he has a quick eye on it.