Update auth chapter (#983)

This commit is contained in:
Lee Robinson
2025-01-21 12:09:06 -06:00
committed by GitHub
parent 7295dab1e7
commit fc6c41c8d1
7 changed files with 421 additions and 408 deletions

View File

@@ -1,5 +1,6 @@
import AcmeLogo from '@/app/ui/acme-logo';
import LoginForm from '@/app/ui/login-form';
import { Suspense } from 'react';
export default function LoginPage() {
return (
@@ -10,7 +11,9 @@ export default function LoginPage() {
<AcmeLogo />
</div>
</div>
<LoginForm />
<Suspense>
<LoginForm />
</Suspense>
</div>
</main>
);

View File

@@ -21,7 +21,7 @@ export default function SideNav() {
<form
action={async () => {
'use server';
await signOut();
await signOut({ redirectTo: '/' });
}}
>
<button className="flex h-[48px] w-full grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3">

View File

@@ -1,6 +1,5 @@
'use client';
import { authenticate } from '@/app/lib/actions';
import { lusitana } from '@/app/ui/fonts';
import {
AtSymbolIcon,
@@ -8,10 +7,14 @@ import {
ExclamationCircleIcon,
} from '@heroicons/react/24/outline';
import { ArrowRightIcon } from '@heroicons/react/20/solid';
import { Button } from './button';
import { Button } from '@/app/ui/button';
import { useActionState } from 'react';
import { authenticate } from '@/app/lib/actions';
import { useSearchParams } from 'next/navigation';
export default function LoginForm() {
const searchParams = useSearchParams();
const callbackUrl = searchParams.get('callbackUrl') || '/dashboard';
const [errorMessage, formAction, isPending] = useActionState(
authenticate,
undefined,
@@ -64,6 +67,7 @@ export default function LoginForm() {
</div>
</div>
</div>
<input type="hidden" name="redirectTo" value={callbackUrl} />
<Button className="mt-4 w-full" aria-disabled={isPending}>
Log in <ArrowRightIcon className="ml-auto h-5 w-5 text-gray-50" />
</Button>