       xhrFields:
         withCredentials: true
       success: (data) ->
+        provider.docStoreLoadedCallback()
         provider._loginSuccessful(data)
       error: ->
-        # nothing yet
+        provider.docStoreLoadedCallback()
 
   _loginWindow: null
 

  @Name: 'documentStore'

  authorized: (@authCallback) ->

  authorize: ->
    @_showLoginWindow()
    @_checkLogin()

  _loginSuccessful: (data) ->
    if @_loginWindow then @_loginWindow.close()

DocumentStoreAuthorizationDialog = React.createFactory React.createClass
  displayName: 'DocumentStoreAuthorizationDialog'

  getInitialState: ->
    docStoreAvailable: false

  componentWillMount: ->
    @props.provider._onDocStoreLoaded =>
      @setState docStoreAvailable: true

  authenticate: ->
    @props.provider.authorize()

  render: ->
    (div {},
      if @state.docStoreAvailable
        (button {onClick: @authenticate}, 'Authorization Needed')
      else
        'Trying to log into the Document Store...'
    )

class DocumentStoreProvider extends ProviderInterface
