aboutsummaryrefslogtreecommitdiff
path: root/src/modules/subscribe.js
blob: e705904cb716cebfbe8e5da0b76c2edd793c2755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import registerPushNotifications from '../services/push/push.js'

const subscribe = {
  state: {
    token: null,
    vapidPublicKey: null
  },
  mutations: {
    setCurrentUser (state, user) {
      state.token = user.credentials
      if (state.token && state.vapidPublicKey) registerPushNotifications(this)
    },
    setInstanceOption (state, { name, value }) {
      if (name !== 'vapidPublicKey') return
      state.vapidPublicKey = value
      if (state.token && state.vapidPublicKey) registerPushNotifications(this)
    }
  }
}

export default subscribe