Set provider programmatically

Im successfully using the migration plugin to call certain scripts on strapi init.

now im trying to pre-configure the github provider with clientId and clientSecret + enabling it.

i only found an old script to do so:
https://gist.githubusercontent.com/isabellachen/b0c8dc99a418a15b24c3ef1d6eec4b7b/raw/6244582ef4a4f9717daaebae2383709c4a5ca8f1/bootstrap-strapi.js

ofc this wont work with a current strapi version.
this is what i’ve got so far:

module.exports = async () => {
  const pluginStore = await strapi.store({
    environment: strapi.config.environment,
    type: 'plugin',
    name: 'users-permissions'
  })

  const grantConfig = {
    github: {
      enabled: true,
      key: 'REPLACED',
      secret: 'REPLACED',
      redirect_uri: '/auth/github/callback',
      scope: ['user', 'user:email']
    }
  }

  const prevGrantConfig = (await pluginStore.get({ key: 'grant' })) || {}

  if (!prevGrantConfig || Object.keys(prevGrantConfig).toString() !== Object.keys(grantConfig).toString()) {
    Object.keys(grantConfig).forEach((key) => {
      if (key in prevGrantConfig) {
        grantConfig[key] = { ...grantConfig[key], ...prevGrantConfig[key] }
      }
    })
    await pluginStore.set({ key: 'grant', value: grantConfig })
  }
}

Can anyone see whats missing or wrong?
Or maybe point me in the right direction?

Thank you soo much :heart:

This topic has been created from a Discord post (1238666950670811176) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

Ive the exact same issue. Even removing prevGrantConfig doesnt change anything…

maybe its a complety wrong way in the first place. it feels soo basic to prepopulate some providers with ENVs

but i could not find anything in the docs

ok i’ve found the solution. your post gave me some ideas.
since im running it as a migration script, it will only run once.
thus:

await pluginStore.set({ key: 'grant', value: { ...prevGrantConfig, ...grantConfig } });

just be sure your grantConfig has the full Object. (or use a deep merge)