Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to avoid hard coding for one signal app_id in init. #30

Open
TakasiVenkataSandeep-08 opened this issue Jun 1, 2021 · 3 comments

Comments

@TakasiVenkataSandeep-08
Copy link

TakasiVenkataSandeep-08 commented Jun 1, 2021

Hi, i am implementing onesignal integration in nuxt js but i am unable to replace the hardcoded one signal ids in nuxt config because i am unable to access environment variables while deploying.

currently my onesignal config looks like this:

oneSignal: {
    cdn: true,
    init: {
      appId: "hard-coded-id",
      safari_web_id: "hard-coded-id",
      allowLocalhostAsSecureOrigin: true,
      welcomeNotification: {
        disable: true,
      },
    }
  },

need to modify it like:

  oneSignal: {
    cdn: true,
    init: {
      appId: process.env.APP_ID,
      safari_web_id: process.env.SAFARI_WEB_ID,
      allowLocalhostAsSecureOrigin: true,
      welcomeNotification: {
        disable: true,
      },
    }
  },

is there any way out?

@fahmifitu
Copy link

fahmifitu commented Feb 15, 2022

I have been able to do it by using nuxt's extendPlugins to remove one-signal.js plugin then including my own one signal plugin which initiate the one signal instance with config from an api call.

@Gazoon007
Copy link

I have been able to do it by using nuxt's extendPlugins to remove one-signal.js plugin then including my own onesignal plugin which initiate the onesignal instance with config from an api call.

@fahmifitu Could you please elaborate with an example code, as I have a hard time understanding how to do it

@fahmifitu
Copy link

fahmifitu commented Jul 28, 2022

@Gazoon007

Sure thing. check below

// in nuxt.config.js, add:
extendPlugins(plugins) {
    // remove /one-signal.js
    return plugins.filter(
      ({ src }) => (src && !src.includes('/onesignal.js')) || !src
    )
},

// add a new nuxt plugin
window.$OneSignal = window.OneSignal = window.OneSignal || []

export default function ({ $axios }, inject) {
  $axios.get("EXAMPLE").then((RESPONSE) => {
    const init = {
      appId: RESPONSE.app_id,
      allowLocalhostAsSecureOrigin: true,
      autoRegister: true,
      autoResubscribe: true,
      notifyButton: {
        enable: false,
      },
    };

    window.OneSignal.push(['init', init])
    inject('OneSignal', window.OneSignal)
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants