/** * The UI that's displayed when loading the root page of the OpenAuth server. You can configure * which providers should be displayed in the select UI. * * ```ts * import { Select } from "@openauthjs/openauth/ui/select" * * export default issuer({ * select: Select({ * providers: { * github: { * hide: true * }, * google: { * display: "Google" * } * } * }) * // ... * }) * ``` * * @packageDocumentation */ /** @jsxImportSource hono/jsx */ import { Layout } from "./base.js" export interface SelectProps { /** * An object with all the providers and their config; where the key is the provider name. * * @example * ```ts * { * github: { * hide: true * }, * google: { * display: "Google" * } * } * ``` */ providers?: Record< string, { /** * Whether to hide the provider from the select UI. * @default false */ hide?: boolean /** * The display name of the provider. */ display?: string } > } export function Select(props?: SelectProps) { return async ( providers: Record, _req: Request, ): Promise => { const jsx = (
{Object.entries(providers).map(([key, type]) => { const match = props?.providers?.[key] if (match?.hide) return const icon = ICON[key] return ( {icon && {icon}} Continue with {match?.display || DISPLAY[type] || type} ) })}
) return new Response(jsx.toString(), { headers: { "Content-Type": "text/html", }, }) } } const DISPLAY: Record = { twitch: "Twitch", google: "Google", github: "GitHub", apple: "Apple", x: "X", facebook: "Facebook", microsoft: "Microsoft", slack: "Slack", } const ICON: Record = { code: ( ), password: ( ), twitch: ( ), google: ( ), github: ( ), apple: ( ), x: ( ), microsoft: ( ), facebook: ( ), slack: ( ), }