No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Call store action after IOS notification received

    Help
    1
    2
    137
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      awipf last edited by

      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 });
      
              window.plugins.OneSignal.startInit(appId)
      
              if (initCallback) {
                initCallback(window.plugins.OneSignal)
              }
      
              window.plugins.OneSignal.handleNotificationOpened(function(openResult) {
      
                store.dispatch("user/loadProfile").then((res) => {
                  router.push({ name: "profile" }).catch(() => {}); 
                })
           
              })
      
              window.plugins.OneSignal.endInit()
            }, false)
          },
      
          optIn (externalUserId) {
            window.plugins.OneSignal.setExternalUserId(externalUserId)
          },
      
          optOut () {
            window.plugins.OneSignal.removeExternalUserId()
          }
        }
      }
      

      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?

      1 Reply Last reply Reply Quote 0
      • A
        awipf last edited by

        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)
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post