logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

users.js (23656B)


  1. import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
  2. import { windowWidth, windowHeight } from '../services/window_utils/window_utils'
  3. import oauthApi from '../services/new_api/oauth.js'
  4. import { compact, map, each, mergeWith, last, concat, uniq, isArray } from 'lodash'
  5. import { registerPushNotifications, unregisterPushNotifications } from '../services/sw/sw.js'
  6. // TODO: Unify with mergeOrAdd in statuses.js
  7. export const mergeOrAdd = (arr, obj, item) => {
  8. if (!item) { return false }
  9. const oldItem = obj[item.id]
  10. if (oldItem) {
  11. // We already have this, so only merge the new info.
  12. mergeWith(oldItem, item, mergeArrayLength)
  13. return { item: oldItem, new: false }
  14. } else {
  15. // This is a new item, prepare it
  16. arr.push(item)
  17. obj[item.id] = item
  18. return { item, new: true }
  19. }
  20. }
  21. const mergeArrayLength = (oldValue, newValue) => {
  22. if (isArray(oldValue) && isArray(newValue)) {
  23. oldValue.length = newValue.length
  24. return mergeWith(oldValue, newValue, mergeArrayLength)
  25. }
  26. }
  27. const getNotificationPermission = () => {
  28. const Notification = window.Notification
  29. if (!Notification) return Promise.resolve(null)
  30. if (Notification.permission === 'default') return Notification.requestPermission()
  31. return Promise.resolve(Notification.permission)
  32. }
  33. const blockUser = (store, id) => {
  34. return store.rootState.api.backendInteractor.blockUser({ id })
  35. .then((relationship) => {
  36. store.commit('updateUserRelationship', [relationship])
  37. store.commit('addBlockId', id)
  38. store.commit('removeStatus', { timeline: 'friends', userId: id })
  39. store.commit('removeStatus', { timeline: 'public', userId: id })
  40. store.commit('removeStatus', { timeline: 'publicAndExternal', userId: id })
  41. })
  42. }
  43. const unblockUser = (store, id) => {
  44. return store.rootState.api.backendInteractor.unblockUser({ id })
  45. .then((relationship) => store.commit('updateUserRelationship', [relationship]))
  46. }
  47. const removeUserFromFollowers = (store, id) => {
  48. return store.rootState.api.backendInteractor.removeUserFromFollowers({ id })
  49. .then((relationship) => store.commit('updateUserRelationship', [relationship]))
  50. }
  51. const editUserNote = (store, { id, comment }) => {
  52. return store.rootState.api.backendInteractor.editUserNote({ id, comment })
  53. .then((relationship) => store.commit('updateUserRelationship', [relationship]))
  54. }
  55. const muteUser = (store, args) => {
  56. const id = typeof args === 'object' ? args.id : args
  57. const expiresIn = typeof args === 'object' ? args.expiresIn : 0
  58. const predictedRelationship = store.state.relationships[id] || { id }
  59. predictedRelationship.muting = true
  60. store.commit('updateUserRelationship', [predictedRelationship])
  61. store.commit('addMuteId', id)
  62. return store.rootState.api.backendInteractor.muteUser({ id, expiresIn })
  63. .then((relationship) => {
  64. store.commit('updateUserRelationship', [relationship])
  65. store.commit('addMuteId', id)
  66. })
  67. }
  68. const unmuteUser = (store, id) => {
  69. const predictedRelationship = store.state.relationships[id] || { id }
  70. predictedRelationship.muting = false
  71. store.commit('updateUserRelationship', [predictedRelationship])
  72. return store.rootState.api.backendInteractor.unmuteUser({ id })
  73. .then((relationship) => store.commit('updateUserRelationship', [relationship]))
  74. }
  75. const hideReblogs = (store, userId) => {
  76. return store.rootState.api.backendInteractor.followUser({ id: userId, reblogs: false })
  77. .then((relationship) => {
  78. store.commit('updateUserRelationship', [relationship])
  79. })
  80. }
  81. const showReblogs = (store, userId) => {
  82. return store.rootState.api.backendInteractor.followUser({ id: userId, reblogs: true })
  83. .then((relationship) => store.commit('updateUserRelationship', [relationship]))
  84. }
  85. const muteDomain = (store, domain) => {
  86. return store.rootState.api.backendInteractor.muteDomain({ domain })
  87. .then(() => store.commit('addDomainMute', domain))
  88. }
  89. const unmuteDomain = (store, domain) => {
  90. return store.rootState.api.backendInteractor.unmuteDomain({ domain })
  91. .then(() => store.commit('removeDomainMute', domain))
  92. }
  93. export const mutations = {
  94. tagUser (state, { user: { id }, tag }) {
  95. const user = state.usersObject[id]
  96. const tags = user.tags || []
  97. const newTags = tags.concat([tag])
  98. user.tags = newTags
  99. },
  100. untagUser (state, { user: { id }, tag }) {
  101. const user = state.usersObject[id]
  102. const tags = user.tags || []
  103. const newTags = tags.filter(t => t !== tag)
  104. user.tags = newTags
  105. },
  106. updateRight (state, { user: { id }, right, value }) {
  107. const user = state.usersObject[id]
  108. const newRights = user.rights
  109. newRights[right] = value
  110. user.rights = newRights
  111. },
  112. updateActivationStatus (state, { user: { id }, deactivated }) {
  113. const user = state.usersObject[id]
  114. user.deactivated = deactivated
  115. },
  116. setCurrentUser (state, user) {
  117. state.lastLoginName = user.screen_name
  118. state.currentUser = mergeWith(state.currentUser || {}, user, mergeArrayLength)
  119. },
  120. clearCurrentUser (state) {
  121. state.currentUser = false
  122. state.lastLoginName = false
  123. },
  124. beginLogin (state) {
  125. state.loggingIn = true
  126. },
  127. endLogin (state) {
  128. state.loggingIn = false
  129. },
  130. saveFriendIds (state, { id, friendIds }) {
  131. const user = state.usersObject[id]
  132. user.friendIds = uniq(concat(user.friendIds || [], friendIds))
  133. },
  134. saveFollowerIds (state, { id, followerIds }) {
  135. const user = state.usersObject[id]
  136. user.followerIds = uniq(concat(user.followerIds || [], followerIds))
  137. },
  138. // Because frontend doesn't have a reason to keep these stuff in memory
  139. // outside of viewing someones user profile.
  140. clearFriends (state, userId) {
  141. const user = state.usersObject[userId]
  142. if (user) {
  143. user.friendIds = []
  144. }
  145. },
  146. clearFollowers (state, userId) {
  147. const user = state.usersObject[userId]
  148. if (user) {
  149. user.followerIds = []
  150. }
  151. },
  152. addNewUsers (state, users) {
  153. each(users, (user) => {
  154. if (user.relationship) {
  155. state.relationships[user.relationship.id] = user.relationship
  156. }
  157. const res = mergeOrAdd(state.users, state.usersObject, user)
  158. const item = res.item
  159. if (res.new && item.screen_name && !item.screen_name.includes('@')) {
  160. state.usersByNameObject[item.screen_name.toLowerCase()] = item
  161. }
  162. })
  163. },
  164. updateUserRelationship (state, relationships) {
  165. relationships.forEach((relationship) => {
  166. state.relationships[relationship.id] = relationship
  167. })
  168. },
  169. updateUserInLists (state, { id, inLists }) {
  170. state.usersObject[id].inLists = inLists
  171. },
  172. saveBlockIds (state, blockIds) {
  173. state.currentUser.blockIds = blockIds
  174. },
  175. addBlockId (state, blockId) {
  176. if (state.currentUser.blockIds.indexOf(blockId) === -1) {
  177. state.currentUser.blockIds.push(blockId)
  178. }
  179. },
  180. setBlockIdsMaxId (state, blockIdsMaxId) {
  181. state.currentUser.blockIdsMaxId = blockIdsMaxId
  182. },
  183. saveMuteIds (state, muteIds) {
  184. state.currentUser.muteIds = muteIds
  185. },
  186. setMuteIdsMaxId (state, muteIdsMaxId) {
  187. state.currentUser.muteIdsMaxId = muteIdsMaxId
  188. },
  189. addMuteId (state, muteId) {
  190. if (state.currentUser.muteIds.indexOf(muteId) === -1) {
  191. state.currentUser.muteIds.push(muteId)
  192. }
  193. },
  194. saveDomainMutes (state, domainMutes) {
  195. state.currentUser.domainMutes = domainMutes
  196. },
  197. addDomainMute (state, domain) {
  198. if (state.currentUser.domainMutes.indexOf(domain) === -1) {
  199. state.currentUser.domainMutes.push(domain)
  200. }
  201. },
  202. removeDomainMute (state, domain) {
  203. const index = state.currentUser.domainMutes.indexOf(domain)
  204. if (index !== -1) {
  205. state.currentUser.domainMutes.splice(index, 1)
  206. }
  207. },
  208. setPinnedToUser (state, status) {
  209. const user = state.usersObject[status.user.id]
  210. user.pinnedStatusIds = user.pinnedStatusIds || []
  211. const index = user.pinnedStatusIds.indexOf(status.id)
  212. if (status.pinned && index === -1) {
  213. user.pinnedStatusIds.push(status.id)
  214. } else if (!status.pinned && index !== -1) {
  215. user.pinnedStatusIds.splice(index, 1)
  216. }
  217. },
  218. setUserForStatus (state, status) {
  219. status.user = state.usersObject[status.user.id]
  220. },
  221. setUserForNotification (state, notification) {
  222. if (notification.type !== 'follow') {
  223. notification.action.user = state.usersObject[notification.action.user.id]
  224. }
  225. notification.from_profile = state.usersObject[notification.from_profile.id]
  226. },
  227. setColor (state, { user: { id }, highlighted }) {
  228. const user = state.usersObject[id]
  229. user.highlight = highlighted
  230. },
  231. signUpPending (state) {
  232. state.signUpPending = true
  233. state.signUpErrors = []
  234. state.signUpNotice = {}
  235. },
  236. signUpSuccess (state) {
  237. state.signUpPending = false
  238. },
  239. signUpFailure (state, errors) {
  240. state.signUpPending = false
  241. state.signUpErrors = errors
  242. state.signUpNotice = {}
  243. },
  244. signUpNotice (state, notice) {
  245. state.signUpPending = false
  246. state.signUpErrors = []
  247. state.signUpNotice = notice
  248. }
  249. }
  250. export const getters = {
  251. findUser: state => query => {
  252. return state.usersObject[query]
  253. },
  254. findUserByName: state => query => {
  255. return state.usersByNameObject[query.toLowerCase()]
  256. },
  257. findUserByUrl: state => query => {
  258. return state.users
  259. .find(u => u.statusnet_profile_url &&
  260. u.statusnet_profile_url.toLowerCase() === query.toLowerCase())
  261. },
  262. relationship: state => id => {
  263. const rel = id && state.relationships[id]
  264. return rel || { id, loading: true }
  265. }
  266. }
  267. export const defaultState = {
  268. loggingIn: false,
  269. lastLoginName: false,
  270. currentUser: false,
  271. users: [],
  272. usersObject: {},
  273. usersByNameObject: {},
  274. signUpPending: false,
  275. signUpErrors: [],
  276. signUpNotice: {},
  277. relationships: {}
  278. }
  279. const users = {
  280. state: defaultState,
  281. mutations,
  282. getters,
  283. actions: {
  284. fetchUserIfMissing (store, id) {
  285. if (!store.getters.findUser(id)) {
  286. store.dispatch('fetchUser', id)
  287. }
  288. },
  289. fetchUser (store, id) {
  290. return store.rootState.api.backendInteractor.fetchUser({ id })
  291. .then((user) => {
  292. store.commit('addNewUsers', [user])
  293. return user
  294. })
  295. },
  296. fetchUserByName (store, name) {
  297. return store.rootState.api.backendInteractor.fetchUserByName({ name })
  298. .then((user) => {
  299. store.commit('addNewUsers', [user])
  300. return user
  301. })
  302. },
  303. fetchUserRelationship (store, id) {
  304. if (store.state.currentUser) {
  305. store.rootState.api.backendInteractor.fetchUserRelationship({ id })
  306. .then((relationships) => store.commit('updateUserRelationship', relationships))
  307. }
  308. },
  309. fetchUserInLists (store, id) {
  310. if (store.state.currentUser) {
  311. store.rootState.api.backendInteractor.fetchUserInLists({ id })
  312. .then((inLists) => store.commit('updateUserInLists', { id, inLists }))
  313. }
  314. },
  315. fetchBlocks (store, args) {
  316. const { reset } = args || {}
  317. const maxId = store.state.currentUser.blockIdsMaxId
  318. return store.rootState.api.backendInteractor.fetchBlocks({ maxId })
  319. .then((blocks) => {
  320. if (reset) {
  321. store.commit('saveBlockIds', map(blocks, 'id'))
  322. } else {
  323. map(blocks, 'id').map(id => store.commit('addBlockId', id))
  324. }
  325. if (blocks.length) {
  326. store.commit('setBlockIdsMaxId', last(blocks).id)
  327. }
  328. store.commit('addNewUsers', blocks)
  329. return blocks
  330. })
  331. },
  332. blockUser (store, id) {
  333. return blockUser(store, id)
  334. },
  335. unblockUser (store, id) {
  336. return unblockUser(store, id)
  337. },
  338. removeUserFromFollowers (store, id) {
  339. return removeUserFromFollowers(store, id)
  340. },
  341. blockUsers (store, ids = []) {
  342. return Promise.all(ids.map(id => blockUser(store, id)))
  343. },
  344. unblockUsers (store, ids = []) {
  345. return Promise.all(ids.map(id => unblockUser(store, id)))
  346. },
  347. editUserNote (store, args) {
  348. return editUserNote(store, args)
  349. },
  350. fetchMutes (store, args) {
  351. const { reset } = args || {}
  352. const maxId = store.state.currentUser.muteIdsMaxId
  353. return store.rootState.api.backendInteractor.fetchMutes({ maxId })
  354. .then((mutes) => {
  355. if (reset) {
  356. store.commit('saveMuteIds', map(mutes, 'id'))
  357. } else {
  358. map(mutes, 'id').map(id => store.commit('addMuteId', id))
  359. }
  360. if (mutes.length) {
  361. store.commit('setMuteIdsMaxId', last(mutes).id)
  362. }
  363. store.commit('addNewUsers', mutes)
  364. return mutes
  365. })
  366. },
  367. muteUser (store, id) {
  368. return muteUser(store, id)
  369. },
  370. unmuteUser (store, id) {
  371. return unmuteUser(store, id)
  372. },
  373. hideReblogs (store, id) {
  374. return hideReblogs(store, id)
  375. },
  376. showReblogs (store, id) {
  377. return showReblogs(store, id)
  378. },
  379. muteUsers (store, ids = []) {
  380. return Promise.all(ids.map(id => muteUser(store, id)))
  381. },
  382. unmuteUsers (store, ids = []) {
  383. return Promise.all(ids.map(id => unmuteUser(store, id)))
  384. },
  385. fetchDomainMutes (store) {
  386. return store.rootState.api.backendInteractor.fetchDomainMutes()
  387. .then((domainMutes) => {
  388. store.commit('saveDomainMutes', domainMutes)
  389. return domainMutes
  390. })
  391. },
  392. muteDomain (store, domain) {
  393. return muteDomain(store, domain)
  394. },
  395. unmuteDomain (store, domain) {
  396. return unmuteDomain(store, domain)
  397. },
  398. muteDomains (store, domains = []) {
  399. return Promise.all(domains.map(domain => muteDomain(store, domain)))
  400. },
  401. unmuteDomains (store, domain = []) {
  402. return Promise.all(domain.map(domain => unmuteDomain(store, domain)))
  403. },
  404. fetchFriends ({ rootState, commit }, id) {
  405. const user = rootState.users.usersObject[id]
  406. const maxId = last(user.friendIds)
  407. return rootState.api.backendInteractor.fetchFriends({ id, maxId })
  408. .then((friends) => {
  409. commit('addNewUsers', friends)
  410. commit('saveFriendIds', { id, friendIds: map(friends, 'id') })
  411. return friends
  412. })
  413. },
  414. fetchFollowers ({ rootState, commit }, id) {
  415. const user = rootState.users.usersObject[id]
  416. const maxId = last(user.followerIds)
  417. return rootState.api.backendInteractor.fetchFollowers({ id, maxId })
  418. .then((followers) => {
  419. commit('addNewUsers', followers)
  420. commit('saveFollowerIds', { id, followerIds: map(followers, 'id') })
  421. return followers
  422. })
  423. },
  424. clearFriends ({ commit }, userId) {
  425. commit('clearFriends', userId)
  426. },
  427. clearFollowers ({ commit }, userId) {
  428. commit('clearFollowers', userId)
  429. },
  430. subscribeUser ({ rootState, commit }, id) {
  431. return rootState.api.backendInteractor.subscribeUser({ id })
  432. .then((relationship) => commit('updateUserRelationship', [relationship]))
  433. },
  434. unsubscribeUser ({ rootState, commit }, id) {
  435. return rootState.api.backendInteractor.unsubscribeUser({ id })
  436. .then((relationship) => commit('updateUserRelationship', [relationship]))
  437. },
  438. toggleActivationStatus ({ rootState, commit }, { user }) {
  439. const api = user.deactivated ? rootState.api.backendInteractor.activateUser : rootState.api.backendInteractor.deactivateUser
  440. api({ user })
  441. .then((user) => { const deactivated = !user.is_active; commit('updateActivationStatus', { user, deactivated }) })
  442. },
  443. registerPushNotifications (store) {
  444. const token = store.state.currentUser.credentials
  445. const vapidPublicKey = store.rootState.instance.vapidPublicKey
  446. const isEnabled = store.rootState.config.webPushNotifications
  447. const notificationVisibility = store.rootState.config.notificationVisibility
  448. registerPushNotifications(isEnabled, vapidPublicKey, token, notificationVisibility)
  449. },
  450. unregisterPushNotifications (store) {
  451. const token = store.state.currentUser.credentials
  452. unregisterPushNotifications(token)
  453. },
  454. addNewUsers ({ commit }, users) {
  455. commit('addNewUsers', users)
  456. },
  457. addNewStatuses (store, { statuses }) {
  458. const users = map(statuses, 'user')
  459. const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
  460. store.commit('addNewUsers', users)
  461. store.commit('addNewUsers', retweetedUsers)
  462. each(statuses, (status) => {
  463. // Reconnect users to statuses
  464. store.commit('setUserForStatus', status)
  465. // Set pinned statuses to user
  466. store.commit('setPinnedToUser', status)
  467. })
  468. each(compact(map(statuses, 'retweeted_status')), (status) => {
  469. // Reconnect users to retweets
  470. store.commit('setUserForStatus', status)
  471. // Set pinned retweets to user
  472. store.commit('setPinnedToUser', status)
  473. })
  474. },
  475. addNewNotifications (store, { notifications }) {
  476. const users = map(notifications, 'from_profile')
  477. const targetUsers = map(notifications, 'target').filter(_ => _)
  478. const notificationIds = notifications.map(_ => _.id)
  479. store.commit('addNewUsers', users)
  480. store.commit('addNewUsers', targetUsers)
  481. const notificationsObject = store.rootState.notifications.idStore
  482. const relevantNotifications = Object.entries(notificationsObject)
  483. .filter(([k, val]) => notificationIds.includes(k))
  484. .map(([k, val]) => val)
  485. // Reconnect users to notifications
  486. each(relevantNotifications, (notification) => {
  487. store.commit('setUserForNotification', notification)
  488. })
  489. },
  490. searchUsers ({ rootState, commit }, { query }) {
  491. return rootState.api.backendInteractor.searchUsers({ query })
  492. .then((users) => {
  493. commit('addNewUsers', users)
  494. return users
  495. })
  496. },
  497. async signUp (store, userInfo) {
  498. store.commit('signUpPending')
  499. const rootState = store.rootState
  500. try {
  501. const data = await rootState.api.backendInteractor.register(
  502. { params: { ...userInfo } }
  503. )
  504. if (data.access_token) {
  505. store.commit('signUpSuccess')
  506. store.commit('setToken', data.access_token)
  507. store.dispatch('loginUser', data.access_token)
  508. return 'ok'
  509. } else { // Request succeeded, but user cannot login yet.
  510. store.commit('signUpNotice', data)
  511. return 'request_sent'
  512. }
  513. } catch (e) {
  514. const errors = e.message
  515. store.commit('signUpFailure', errors)
  516. throw e
  517. }
  518. },
  519. async getCaptcha (store) {
  520. return store.rootState.api.backendInteractor.getCaptcha()
  521. },
  522. logout (store) {
  523. const { oauth, instance } = store.rootState
  524. const data = {
  525. ...oauth,
  526. commit: store.commit,
  527. instance: instance.server
  528. }
  529. return oauthApi.getOrCreateApp(data)
  530. .then((app) => {
  531. const params = {
  532. app,
  533. instance: data.instance,
  534. token: oauth.userToken
  535. }
  536. return oauthApi.revokeToken(params)
  537. })
  538. .then(() => {
  539. store.commit('clearCurrentUser')
  540. store.dispatch('disconnectFromSocket')
  541. store.commit('clearToken')
  542. store.dispatch('stopFetchingTimeline', 'friends')
  543. store.commit('setBackendInteractor', backendInteractorService(store.getters.getToken()))
  544. store.dispatch('stopFetchingNotifications')
  545. store.dispatch('stopFetchingLists')
  546. store.dispatch('stopFetchingFollowRequests')
  547. store.commit('clearNotifications')
  548. store.commit('resetStatuses')
  549. store.dispatch('resetChats')
  550. store.dispatch('setLastTimeline', 'public-timeline')
  551. store.dispatch('setLayoutWidth', windowWidth())
  552. store.dispatch('setLayoutHeight', windowHeight())
  553. store.commit('clearServerSideStorage')
  554. })
  555. },
  556. loginUser (store, accessToken) {
  557. return new Promise((resolve, reject) => {
  558. const commit = store.commit
  559. const dispatch = store.dispatch
  560. commit('beginLogin')
  561. store.rootState.api.backendInteractor.verifyCredentials(accessToken)
  562. .then((data) => {
  563. if (!data.error) {
  564. const user = data
  565. // user.credentials = userCredentials
  566. user.credentials = accessToken
  567. user.blockIds = []
  568. user.muteIds = []
  569. user.domainMutes = []
  570. commit('setCurrentUser', user)
  571. commit('setServerSideStorage', user)
  572. commit('addNewUsers', [user])
  573. dispatch('fetchEmoji')
  574. getNotificationPermission()
  575. .then(permission => commit('setNotificationPermission', permission))
  576. // Set our new backend interactor
  577. commit('setBackendInteractor', backendInteractorService(accessToken))
  578. dispatch('pushServerSideStorage')
  579. if (user.token) {
  580. dispatch('setWsToken', user.token)
  581. // Initialize the shout socket.
  582. dispatch('initializeSocket')
  583. }
  584. const startPolling = () => {
  585. // Start getting fresh posts.
  586. dispatch('startFetchingTimeline', { timeline: 'friends' })
  587. // Start fetching notifications
  588. dispatch('startFetchingNotifications')
  589. // Start fetching chats
  590. dispatch('startFetchingChats')
  591. }
  592. dispatch('startFetchingLists')
  593. if (user.locked) {
  594. dispatch('startFetchingFollowRequests')
  595. }
  596. if (store.getters.mergedConfig.useStreamingApi) {
  597. dispatch('fetchTimeline', { timeline: 'friends', since: null })
  598. dispatch('fetchNotifications', { since: null })
  599. dispatch('enableMastoSockets', true).catch((error) => {
  600. console.error('Failed initializing MastoAPI Streaming socket', error)
  601. }).then(() => {
  602. dispatch('fetchChats', { latest: true })
  603. setTimeout(() => dispatch('setNotificationsSilence', false), 10000)
  604. })
  605. } else {
  606. startPolling()
  607. }
  608. // Get user mutes
  609. dispatch('fetchMutes')
  610. dispatch('setLayoutWidth', windowWidth())
  611. dispatch('setLayoutHeight', windowHeight())
  612. // Fetch our friends
  613. store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
  614. .then((friends) => commit('addNewUsers', friends))
  615. } else {
  616. const response = data.error
  617. // Authentication failed
  618. commit('endLogin')
  619. // remove authentication token on client/authentication errors
  620. if ([400, 401, 403, 422].includes(response.status)) {
  621. commit('clearToken')
  622. }
  623. if (response.status === 401) {
  624. reject(new Error('Wrong username or password'))
  625. } else {
  626. reject(new Error('An error occurred, please try again'))
  627. }
  628. }
  629. commit('endLogin')
  630. resolve()
  631. })
  632. .catch((error) => {
  633. console.error(error)
  634. commit('endLogin')
  635. reject(new Error('Failed to connect to server, try again'))
  636. })
  637. })
  638. }
  639. }
  640. }
  641. export default users