| 1 | import { AUTH_STRATEGY_OPTION } from "../config/options"; |
| 2 | |
| 3 | export const loginFileContent = (options: AUTH_STRATEGY_OPTION[]) => { |
| 4 | const buttons = options |
| 5 | .map( |
| 6 | (option) => |
| 7 | ` <SocialButton provider={AuthStrategies.${option.key.toUpperCase()}} label="Login with ${option.key}" />` |
| 8 | ) |
| 9 | .join("\n"); |
| 10 | return [ |
| 11 | 'import { Form } from "@remix-run/react"', |
| 12 | 'import { AuthStrategies } from "~/services/auth_strategies";', |
| 13 | 'import type { AuthStrategy } from "~/services/auth.server";', |
| 14 | "", |
| 15 | "interface SocialButtonProps {", |
| 16 | " provider: AuthStrategy,", |
| 17 | " label: string", |
| 18 | "}", |
| 19 | "", |
| 20 | "const SocialButton = ({ provider, label }: SocialButtonProps) => (", |
| 21 | ' <Form action={`/auth/${provider}`} method="post">', |
| 22 | " <button>{label}</button>", |
| 23 | " </Form>", |
| 24 | ");", |
| 25 | "", |
| 26 | "export default function LoginRoute() {", |
| 27 | " return (", |
| 28 | " <>", |
| 29 | buttons, |
| 30 | " </>", |
| 31 | " );", |
| 32 | "}", |
| 33 | ].join("\n"); |
| 34 | }; |