aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/routes/login.tsx
blob: 0da26165feaea8a9d8651eafdc2213e96a92301c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { Form } from "@remix-run/react";
import { authenticator } from "../.server/auth";

export async function loader({ request }: LoaderFunctionArgs) {
  return await authenticator.isAuthenticated(request, {
    successRedirect: "/dashboard",
  });
}

export async function action({ request }: ActionFunctionArgs) {
  return await authenticator.authenticate("default", request, {
    successRedirect: "/dashboard",
    failureRedirect: "/login",
  });
}

export default function Login() {
  return (
    <Form method="post">
      <input type="username" name="username" required />
      <input
        type="password"
        name="password"
        autoComplete="current-password"
        required
      />
      <button>Log In</button>
    </Form>
  );
}