Skip to content

Instantly share code, notes, and snippets.

@jhdavids8
Created August 19, 2013 02:45
Show Gist options
  • Save jhdavids8/6265389 to your computer and use it in GitHub Desktop.
Save jhdavids8/6265389 to your computer and use it in GitHub Desktop.
Angular service that fetches and stores the current, logged-in user
angular.module("PathgatherApp").factory 'CurrentUser', (["$q", "Restangular", ($q, Rectangular) ->
current_user = null
current_user_promise = Restangular.all("users").customGET("current")
current_user_promise.then (response) ->
current_user = response
{
getUser: () ->
if current_user?
deferred = $q.defer()
deferred.resolve(current_user)
return deferred.promise
else
return current_user_promise
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment