| 1 | import { WorkspaceConfiguration } from "vscode"; |
| 2 | |
| 3 | export const authProviderFileContent = (config: WorkspaceConfiguration) => { |
| 4 | const runtimeDependency = config.get("runtimeDependency") || "@remix-run/node"; |
| 5 | return [ |
| 6 | `import { redirect } from "${runtimeDependency}"`, |
| 7 | `import type { ActionFunctionArgs } from "${runtimeDependency}"`, |
| 8 | "import { authenticator } from '~/services/auth.server';", |
| 9 | 'import type { AuthStrategy } from "~/services/auth.server";', |
| 10 | "", |
| 11 | "export const loader = () => redirect('/login');", |
| 12 | "", |
| 13 | "export const action = async ({ request, params }: ActionFunctionArgs) => {", |
| 14 | " // If the provider is not specified, redirect to the login page", |
| 15 | " if(!params.provider) return redirect('/login');", |
| 16 | "", |
| 17 | " const provider = params.provider as AuthStrategy;", |
| 18 | "", |
| 19 | " return await authenticator.authenticate(provider, request, {", |
| 20 | ' successRedirect: "/dashboard"', |
| 21 | " });", |
| 22 | "};", |
| 23 | ].join("\n"); |
| 24 | }; |