Skip to content

Commit

Permalink
Adds safety nets in case settings update fails
Browse files Browse the repository at this point in the history
  • Loading branch information
xcambar committed May 27, 2014
1 parent a3680f0 commit 5da3e0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/api/auth.coffee
Expand Up @@ -10,11 +10,21 @@ define ['underscore', '../utils/promises', '../utils/version'], (_, promises, ve
_popupInterval = null

loginComplete = (me)->
emitter.once 'hull.settings.update', ->
dfd = promises.deferred()
promise = dfd.promise
promise.then ->
emitter.emit('hull.auth.login', me)
unless me?.stats?.sign_in_count?
emitter.emit('hull.auth.create', me)
me
, (err)->
emitter.emit('hull.auth.fail', err)
emitter.once 'hull.settings.update', ->
# user has been set, settings have been update. Yay!
dfd.resolve me
# Setup a delay to launch rejection
rejectable = _.bind(dfd.reject, dfd)
_.delay rejectable, 30000, new Error('Timeout for login')
promise

loginFailed = (err)->
emitter.emit('hull.auth.fail', err)
Expand Down
5 changes: 1 addition & 4 deletions src/api/current-user.coffee
Expand Up @@ -6,10 +6,7 @@ define ()->
emitter.on 'hull.auth.login', (me)->
_currentUser = me
emitter.on 'hull.auth.update', (me)->
unless _currentUser?.id
if me.id
emitter.emit 'hull.auth.login', me
else
if _currentUser?.id
if _currentUser.id == me.id
_currentUser = me
else unless me?.id
Expand Down

0 comments on commit 5da3e0b

Please sign in to comment.