diff --git a/app/lib/actions.ts b/app/lib/actions.ts
index 9a82aee..e484118 100644
--- a/app/lib/actions.ts
+++ b/app/lib/actions.ts
@@ -4,6 +4,9 @@ import { z } from 'zod';
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(),
@@ -97,4 +100,23 @@ export async function deleteInvoice(id: string) {
} catch (error) {
return { message: 'Database Error: Failed to Delete Invoice.' };
}
+}
+
+export async function authenticate(
+ prevState: string | undefined,
+ formData: FormData,
+) {
+ try {
+ await signIn('credentials', formData);
+ } catch (error) {
+ if (error instanceof AuthError) {
+ switch (error.type) {
+ case 'CredentialsSignin':
+ return 'Invalid credentials.';
+ default:
+ return 'Something went wrong.';
+ }
+ }
+ throw error;
+ }
}
\ No newline at end of file
diff --git a/app/login/page.tsx b/app/login/page.tsx
new file mode 100644
index 0000000..50a147c
--- /dev/null
+++ b/app/login/page.tsx
@@ -0,0 +1,17 @@
+import AcmeLogo from '@/app/ui/acme-logo';
+import LoginForm from '@/app/ui/login-form';
+
+export default function LoginPage() {
+ return (
+