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:

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

module.exports = async () => {
  const pluginStore = await{
    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.

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

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