mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-29 07:34:15 +00:00
Add code for chapter 15
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import { authenticate } from '@/app/lib/actions';
|
||||
import { lusitana } from '@/app/ui/fonts';
|
||||
import {
|
||||
AtSymbolIcon,
|
||||
@@ -9,14 +8,10 @@ import {
|
||||
} from '@heroicons/react/24/outline';
|
||||
import { ArrowRightIcon } from '@heroicons/react/20/solid';
|
||||
import { Button } from './button';
|
||||
import { useFormState, useFormStatus } from 'react-dom';
|
||||
|
||||
export default function LoginForm() {
|
||||
const [code, action] = useFormState(authenticate, undefined);
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
return (
|
||||
<form action={action} className="space-y-3">
|
||||
<form className="space-y-3">
|
||||
<div className="flex-1 rounded-lg bg-gray-50 px-6 pb-4 pt-8">
|
||||
<h1 className={`${lusitana.className} mb-3 text-2xl`}>
|
||||
Please log in to continue.
|
||||
@@ -62,18 +57,9 @@ export default function LoginForm() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Button className="mt-4 w-full" aria-disabled={pending}>
|
||||
Log in <ArrowRightIcon className="ml-auto h-5 w-5 text-gray-50" />
|
||||
</Button>
|
||||
<LoginButton />
|
||||
<div className="flex h-8 items-end space-x-1">
|
||||
{code === 'CredentialsSignin' && (
|
||||
<>
|
||||
<ExclamationCircleIcon className="h-5 w-5 text-red-500" />
|
||||
<p aria-live="polite" className="text-sm text-red-500">
|
||||
Invalid credentials
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
{/* Add form errors here */}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -81,10 +67,8 @@ export default function LoginForm() {
|
||||
}
|
||||
|
||||
function LoginButton() {
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
return (
|
||||
<Button className="mt-4 w-full" aria-disabled={pending}>
|
||||
<Button className="mt-4 w-full">
|
||||
Log in <ArrowRightIcon className="ml-auto h-5 w-5 text-gray-50" />
|
||||
</Button>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user