SHARE
TWEET

Untitled

a guest Sep 21st, 2019 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     loginUser (store, accessToken) {
  2.       return new Promise((resolve, reject) => {
  3.         const commit = store.commit
  4.         commit('beginLogin')
  5.         store.rootState.api.backendInteractor.verifyCredentials(accessToken)
  6.           .then((data) => {
  7.             if (!data.error) {
  8.               const user = data
  9.               // user.credentials = userCredentials
  10.               user.credentials = accessToken
  11.               user.blockIds = []
  12.               user.muteIds = []
  13.               commit('setCurrentUser', user)
  14.               commit('addNewUsers', [user])
  15.  
  16.               getNotificationPermission()
  17.                 .then(permission => commit('setNotificationPermission', permission))
  18.  
  19.               // Set our new backend interactor
  20.               commit('setBackendInteractor', backendInteractorService(accessToken))
  21.  
  22.               if (user.token) {
  23.                 store.dispatch('setWsToken', user.token)
  24.  
  25.                 // Initialize the chat socket.
  26.                 store.dispatch('initializeSocket')
  27.               }
  28.  
  29.               // Start getting fresh posts.
  30.               store.dispatch('startFetchingTimeline', { timeline: 'friends' })
  31.  
  32.               // Start fetching notifications
  33.               store.dispatch('startFetchingNotifications')
  34.  
  35.               // Get user mutes
  36.               store.dispatch('fetchMutes')
  37.  
  38.               // Fetch our friends
  39.               store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
  40.                 .then((friends) => commit('addNewUsers', friends))
  41.             } else {
  42.               const response = data.error
  43.               // Authentication failed
  44.               commit('endLogin')
  45.               if (response.status === 401) {
  46.                 reject('Wrong username or password')
  47.               } else {
  48.                 reject('An error occurred, please try again')
  49.               }
  50.             }
  51.             commit('endLogin')
  52.             resolve()
  53.           })
  54.         .catch((error) => {
  55.           console.log(error)
  56.           commit('endLogin')
  57.           reject('Failed to connect to server, try again')
  58.         })
  59.       })
  60.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top