Call store action after IOS notification received

  • This is not really a Quasar issue but i implemented IOS notifications using Quasar, Cordova and the OneSignal SDK. the notifications work great but I can’t seem to be able to call a store action from the oneSignal config file after a user clicks on a notification. What i’m trying to do is grab a fresh copy of a user’s profile via an api call when a user clicks a notification and then navigate to the profile page.

    This is my OneSignal config file located in src/boot/one-signal.js directory

    export default async ({ app, router, store ,Vue }) => {
      app.$oneSignal = Vue.prototype.$oneSignal = {
        get instance () {
          return window.plugins && window.plugins.OneSignal
        setup (appId, {initCallback} = {}) {
          if (!appId) {
            throw new Error('boot/one-signal: app id is required')
          document.addEventListener('deviceready', function () {
            window.plugins.OneSignal.setLogLevel({ logLevel: 6, visualLevel: 0 });
            if (initCallback) {
            window.plugins.OneSignal.handleNotificationOpened(function(openResult) {
              store.dispatch("user/loadProfile").then((res) => {
                router.push({ name: "profile" }).catch(() => {}); 
          }, false)
        optIn (externalUserId) {
        optOut () {

    The redirect works, but the loadProfile action is not called and ‘res’ is undefined. I know i could reload in ‘mount’ but most times i don’t want grab a fresh copy. What am i missing here in the way i’m handling it?

  • That was actually a silly mistake. In the action, i don’t call the api if profile is defined in the store already. The solution was to call the action in mount of the profile component. And in one-signal.js commit to null out the profile.

    store.commit("user/setProfile", null)

Log in to reply