mirror of
https://github.com/vercel/next-learn.git
synced 2026-07-08 22:46:01 +00:00
chore: bump next-auth (#491)
* chore: bump `next-auth` * shorten message
This commit is contained in:
@@ -5,6 +5,7 @@ import { sql } from '@vercel/postgres';
|
|||||||
import { revalidatePath } from 'next/cache';
|
import { revalidatePath } from 'next/cache';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { signIn } from '@/auth';
|
import { signIn } from '@/auth';
|
||||||
|
import { AuthError } from 'next-auth';
|
||||||
|
|
||||||
const FormSchema = z.object({
|
const FormSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
@@ -124,10 +125,15 @@ export async function authenticate(
|
|||||||
formData: FormData,
|
formData: FormData,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
await signIn('credentials', Object.fromEntries(formData));
|
await signIn('credentials', formData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if ((error as Error).message.includes('CredentialsSignin')) {
|
if (error instanceof AuthError) {
|
||||||
return 'CredentialsSignin';
|
switch (error.type) {
|
||||||
|
case 'CredentialsSignin':
|
||||||
|
return 'Invalid credentials.';
|
||||||
|
default:
|
||||||
|
return 'Something went wrong.';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { Button } from './button';
|
|||||||
import { useFormState, useFormStatus } from 'react-dom';
|
import { useFormState, useFormStatus } from 'react-dom';
|
||||||
|
|
||||||
export default function LoginForm() {
|
export default function LoginForm() {
|
||||||
const [state, dispatch] = useFormState(authenticate, undefined);
|
const [errorMessage, dispatch] = useFormState(authenticate, undefined);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form action={dispatch} className="space-y-3">
|
<form action={dispatch} className="space-y-3">
|
||||||
@@ -67,10 +67,10 @@ export default function LoginForm() {
|
|||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
aria-atomic="true"
|
aria-atomic="true"
|
||||||
>
|
>
|
||||||
{state === 'CredentialsSignin' && (
|
{errorMessage && (
|
||||||
<>
|
<>
|
||||||
<ExclamationCircleIcon className="h-5 w-5 text-red-500" />
|
<ExclamationCircleIcon className="h-5 w-5 text-red-500" />
|
||||||
<p className="text-sm text-red-500">Invalid credentials</p>
|
<p className="text-sm text-red-500">{errorMessage}</p>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"clsx": "^2.0.0",
|
"clsx": "^2.0.0",
|
||||||
"next": "^14.0.2",
|
"next": "^14.0.2",
|
||||||
"next-auth": "^5.0.0-beta.3",
|
"next-auth": "^5.0.0-beta.4",
|
||||||
"postcss": "8.4.31",
|
"postcss": "8.4.31",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user