diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/pushNotifications.js | 29 | ||||
| -rw-r--r-- | src/modules/users.js | 8 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/modules/pushNotifications.js b/src/modules/pushNotifications.js new file mode 100644 index 00000000..43143b1f --- /dev/null +++ b/src/modules/pushNotifications.js @@ -0,0 +1,29 @@ +import registerPushNotifications from '../services/push/push.js' + +const subscribe = { + state: { + token: null, + vapidPublicKey: null + }, + mutations: { + setApiToken (state, user) { + state.token = user.credentials + }, + setVapidPublicKey (state, vapidPublicKey) { + state.vapidPublicKey = vapidPublicKey + } + + }, + actions: { + setInstanceOption (store, { name, value }) { + store.commit('setVapidPublicKey', value) + if (store.state.token) registerPushNotifications(this) + }, + setCurrentUser (store, user) { + store.commit('setApiToken', user.credentials) + if (store.state.vapidPublicKey) registerPushNotifications(this) + } + } +} + +export default subscribe diff --git a/src/modules/users.js b/src/modules/users.js index d2c7fdf6..1256e9df 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,4 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import registerPushNotifications from '../services/push/push.js' import { compact, map, each, merge } from 'lodash' import { set } from 'vue' @@ -87,6 +86,9 @@ const users = { store.dispatch('stopFetching', 'friends') store.commit('setBackendInteractor', backendInteractorService()) }, + setCurrentUser (store, user) { + store.commit('setCurrentUser', user) + }, loginUser (store, accessToken) { return new Promise((resolve, reject) => { const commit = store.commit @@ -98,7 +100,7 @@ const users = { .then((user) => { // user.credentials = userCredentials user.credentials = accessToken - commit('setCurrentUser', user) + store.dispatch('setCurrentUser', user) commit('addNewUsers', [user]) // Set our new backend interactor @@ -122,8 +124,6 @@ const users = { // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({id: user.id}) .then((friends) => commit('addNewUsers', friends)) - - registerPushNotifications(store) }) } else { // Authentication failed |
