mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import { useRuntimeConfig } from '#imports'
|
|
|
|
const FF_ENABLE_ALL = '*'
|
|
|
|
function getFeatureFlags(env) {
|
|
return (env.FEATURE_FLAGS || '')
|
|
.split(',')
|
|
.map((flag) => flag.trim().toLowerCase())
|
|
}
|
|
|
|
export function featureFlagIsEnabled(featureFlags, flag, store) {
|
|
const name = flag.toLowerCase()
|
|
if (featureFlags.includes(FF_ENABLE_ALL) || featureFlags.includes(name)) {
|
|
return true
|
|
}
|
|
// Sign-out keeps the last user's additional data in the store.
|
|
if (!store.getters['auth/isAuthenticated']) {
|
|
return false
|
|
}
|
|
const userFlags = store.getters['auth/getAdditionalUserData'].feature_flags
|
|
return Boolean(userFlags?.includes(name))
|
|
}
|
|
|
|
export default defineNuxtPlugin({
|
|
name: 'feature-flags',
|
|
dependsOn: ['create-store'],
|
|
setup(nuxtApp) {
|
|
const runtimeConfig = useRuntimeConfig()
|
|
const featureFlagsValue = runtimeConfig.public.featureFlags
|
|
const FEATURE_FLAGS = getFeatureFlags({
|
|
...runtimeConfig.public,
|
|
FEATURE_FLAGS: featureFlagsValue,
|
|
})
|
|
|
|
return {
|
|
provide: {
|
|
featureFlagIsEnabled: (flag) =>
|
|
featureFlagIsEnabled(FEATURE_FLAGS, flag, nuxtApp.$store),
|
|
},
|
|
}
|
|
},
|
|
})
|