           @options.onPermissionFailed()
 
         setTokenSentToServer(false)
-      return
     ).catch (err) ->
       console.log 'An error occurred while retrieving token. ', err
       setTokenSentToServer(false)

    @webPushTokenRegistrationUrl = "#{@options.endPoint}/api/push-subscriptions/#{@options.channelId}"

  subscribe: ->
    @initializeFirebase()
    @getToken()

  initializeFirebase: () ->
    config =
      apiKey: @options.firebaseApiKey
      messagingSenderId: @options.firebaseMessagingSenderId
    firebase.initializeApp config
    @messaging = firebase.messaging()

    @messaging.onMessage (payload) =>

        @options.onErrorRetrievingRefreshedToken()

  getToken: () ->
    @messaging.getToken()
      
  getTokenAndSubscribe: () ->
    @messaging.getToken().then((currentToken) =>
      if currentToken
        @sendTokenToServer currentToken
