Created
August 17, 2021 20:00
-
-
Save rikonor/25acaeb73b1ece3e47702c52ce2b1050 to your computer and use it in GitHub Desktop.
[Strapi] Enable Google Provider via Bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const isFirstRun = async () => { | |
const pluginStore = strapi.store({ | |
environment: "", | |
type: "type", | |
name: "setup", | |
}); | |
const initHasRun = await pluginStore.get({ key: "initHasRun" }); | |
if (!!initHasRun) { | |
return false; | |
} | |
await pluginStore.set({ key: "initHasRun", value: true }); | |
return true; | |
}; | |
const enableGoogleProvider = async () => { | |
const clientId = process.env.PROVIDER_GOOGLE_CLIENT_ID; | |
if (!clientId) throw new Error("Missing PROVIDER_GOOGLE_CLIENT_ID"); | |
const clientSecret = process.env.PROVIDER_GOOGLE_CLIENT_SECRET; | |
if (!clientSecret) throw new Error("Missing PROVIDER_GOOGLE_CLIENT_SECRET"); | |
const pluginStore = strapi.store({ | |
environment: "", | |
type: "plugin", | |
name: "users-permissions", | |
}); | |
const grantConfig = await pluginStore.get({ key: "grant" }); | |
grantConfig["google"] = { | |
...grantConfig["google"], | |
enabled: true, | |
key: clientId, | |
secret: clientSecret, | |
}; | |
await pluginStore.set({ key: "grant", value: grantConfig }); | |
}; | |
/** | |
* An asynchronous bootstrap function that runs before | |
* your application gets started. | |
* | |
* This gives you an opportunity to set up your data model, | |
* run jobs, or perform some special logic. | |
* | |
* See more details here: https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#bootstrap | |
*/ | |
module.exports = async () => { | |
!!(await isFirstRun()) && (await enableGoogleProvider()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment