| 1 | import { WorkspaceConfiguration } from "vscode"; |
| 2 | |
| 3 | export const dashboardFileContent = (config: WorkspaceConfiguration) => { |
| 4 | const runtimeDependency = config.get("runtimeDependency") || "@remix-run/node"; |
| 5 | return [ |
| 6 | `import type { LoaderFunctionArgs } from '${runtimeDependency}';`, |
| 7 | "import { useLoaderData, Form } from '@remix-run/react';", |
| 8 | "import { authenticator } from '~/services/auth.server';", |
| 9 | "", |
| 10 | "export const loader = async ({ request }: LoaderFunctionArgs) => {", |
| 11 | " await authenticator.isAuthenticated(request, {", |
| 12 | ' failureRedirect: "/login",', |
| 13 | " });", |
| 14 | " return { message: 'You are logged in!' };", |
| 15 | "};", |
| 16 | "", |
| 17 | "export default function DashboardRoute() {", |
| 18 | " const { message } = useLoaderData<typeof loader>();", |
| 19 | " return (", |
| 20 | " <div>", |
| 21 | " <h1>{message}</h1>", |
| 22 | " <Form method='post' action='/logout'>", |
| 23 | " <button type='submit'>Logout</button>", |
| 24 | " </Form>", |
| 25 | " </div>", |
| 26 | " );", |
| 27 | "}", |
| 28 | ].join("\n"); |
| 29 | }; |