mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## Context Adds support for multiple custom auth providers in custom-content <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for multiple custom sign-in providers via a new plural configuration. * Updated the sign-in page to render all configured custom provider options while maintaining compatibility with the legacy single-provider setting. * Improved the custom provider button display to remove internal prefixes from provider names. * **Documentation** * Updated the configuration schema, examples, and sample data to document the new multi-provider setting. * Marked the legacy single-provider configuration as deprecated in favor of the plural option. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import customContentRaw from './custom-content.json'
|
|
import { CustomContentTypes } from './CustomContent.types'
|
|
|
|
// [Joshen] See if we can de-dupe any of the logic here with enabled-features
|
|
// For now just getting something working going first
|
|
// Also not sure if CustomContentTypes is the right way to go here with trying to dynamically type
|
|
|
|
const customContentStaticObj = customContentRaw as Omit<typeof customContentRaw, '$schema'>
|
|
type CustomContent = keyof typeof customContentStaticObj
|
|
|
|
type SnakeToCamelCase<S extends string> = S extends `${infer First}_${infer Rest}`
|
|
? `${First}${SnakeToCamelCase<Capitalize<Rest>>}`
|
|
: S
|
|
|
|
type CustomContentToCamelCase<S extends CustomContent> = S extends `${infer P}:${infer R}`
|
|
? `${SnakeToCamelCase<P>}${Capitalize<SnakeToCamelCase<R>>}`
|
|
: SnakeToCamelCase<S>
|
|
|
|
function contentToCamelCase(feature: CustomContent) {
|
|
return feature
|
|
.replace(/:/g, '_')
|
|
.split('_')
|
|
.map((word, index) => (index === 0 ? word : word[0].toUpperCase() + word.slice(1)))
|
|
.join('') as CustomContentToCamelCase<typeof feature>
|
|
}
|
|
|
|
export const useCustomContent = <T extends CustomContent[]>(
|
|
contents: T
|
|
): {
|
|
[key in CustomContentToCamelCase<T[number]>]: CustomContentTypes[key] | null
|
|
} => {
|
|
// [Joshen] Running into some TS errors without the `as` here - must be overlooking something super simple
|
|
return Object.fromEntries(
|
|
contents.map((content) => [contentToCamelCase(content), customContentStaticObj[content]])
|
|
) as {
|
|
[key in CustomContentToCamelCase<T[number]>]: CustomContentTypes[key] | null
|
|
}
|
|
}
|