import { Link, Form, useActionData } from "@remix-run/react"; import type { ActionFunction, LoaderFunction } from "@remix-run/node"; import Button from "~/components/button"; import Callout from "~/components/callout"; import Logo from "~/components/logo"; import { authenticator } from "~/services/auth.server"; type LoaderData = { error: boolean }; export const action: ActionFunction = async ({ request, context }) => { try { await authenticator.authenticate("user-pass", request, { successRedirect: "/", context, // optional }); } catch (err: any) { if ("status" in err && err.status === 302) { throw err; } console.log("==="); console.log(err); return { error: true }; } return { error: false }; }; // dashboard if it is or return null if it's not export let loader: LoaderFunction = async ({ request }) => { // If the user is already authenticated redirect to /dashboard directly await authenticator.isAuthenticated(request, { successRedirect: "/", }); return true; }; export default function Screen() { const data = useActionData(); return (
A doctor in background
); }