Skip to content

Commit

Permalink
chore: bump next-auth (#491)
Browse files Browse the repository at this point in the history
* chore: bump `next-auth`

* shorten message
balazsorban44 authored Nov 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7fc5092 commit e75f714
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 9 additions & 3 deletions dashboard/final-example/app/lib/actions.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import { sql } from '@vercel/postgres';
import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';
import { signIn } from '@/auth';
import { AuthError } from 'next-auth';

const FormSchema = z.object({
id: z.string(),
@@ -124,10 +125,15 @@ export async function authenticate(
formData: FormData,
) {
try {
await signIn('credentials', Object.fromEntries(formData));
await signIn('credentials', formData);
} catch (error) {
if ((error as Error).message.includes('CredentialsSignin')) {
return 'CredentialsSignin';
if (error instanceof AuthError) {
switch (error.type) {
case 'CredentialsSignin':
return 'Invalid credentials.';
default:
return 'Something went wrong.';
}
}
throw error;
}
6 changes: 3 additions & 3 deletions dashboard/final-example/app/ui/login-form.tsx
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import { Button } from './button';
import { useFormState, useFormStatus } from 'react-dom';

export default function LoginForm() {
const [state, dispatch] = useFormState(authenticate, undefined);
const [errorMessage, dispatch] = useFormState(authenticate, undefined);

return (
<form action={dispatch} className="space-y-3">
@@ -67,10 +67,10 @@ export default function LoginForm() {
aria-live="polite"
aria-atomic="true"
>
{state === 'CredentialsSignin' && (
{errorMessage && (
<>
<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>
2 changes: 1 addition & 1 deletion dashboard/final-example/package.json
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
"bcrypt": "^5.1.1",
"clsx": "^2.0.0",
"next": "^14.0.2",
"next-auth": "^5.0.0-beta.3",
"next-auth": "^5.0.0-beta.4",
"postcss": "8.4.31",
"react": "18.2.0",
"react-dom": "18.2.0",

1 comment on commit e75f714

@vercel
Copy link

@vercel vercel bot commented on e75f714 Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-learn-dashboard – ./dashboard/final-example

next-learn-dashboard.vercel.sh
next-learn-dashboard-git-main.vercel.sh

Please sign in to comment.