-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
_.auth.login.tsx
49 lines (41 loc) · 1.23 KB
/
_.auth.login.tsx
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type {
ActionFunctionArgs,
LoaderFunctionArgs,
} from "@remix-run/cloudflare";
import { json, redirect } from "@remix-run/cloudflare";
import { useT } from "~/helpers/use-i18n.hook";
import { Auth } from "~/modules/auth.server";
import { SessionStorage } from "~/modules/session.server";
import { Button } from "~/ui/Button";
import { Form } from "~/ui/Form";
export async function loader({ request, context }: LoaderFunctionArgs) {
let user = await SessionStorage.readUser(context, request);
if (!user) return json(null);
throw redirect("/");
}
export async function action({ request, context }: ActionFunctionArgs) {
let auth = new Auth(context);
return await auth.authenticate("github", request, {
successRedirect: "/auth/github/callback",
failureRedirect: "/auth/login",
});
}
export default function Component() {
let t = useT("login");
return (
<Form
method="post"
className="mx-auto flex max-w-screen-sm flex-col items-center gap-10 pt-10"
reloadDocument
>
<header className="sm:mx-auto sm:w-full sm:max-w-md">
<h2 className="text-center text-3xl font-bold tracking-tight">
{t("title")}
</h2>
</header>
<Button type="submit" variant="primary">
{t("github")}
</Button>
</Form>
);
}