diff --git a/alimento-nextjs/actions/Admin/admin-login.tsx b/alimento-nextjs/actions/Admin/admin-login.tsx
new file mode 100644
index 0000000..6bc9c48
--- /dev/null
+++ b/alimento-nextjs/actions/Admin/admin-login.tsx
@@ -0,0 +1,30 @@
+'use server';
+import { generateAndSendOTP } from '@/lib/auth';
+import prismadb from '@/lib/prismadb';
+import { Prisma, Admin } from '@prisma/client';
+
+export async function AdminVerify({
+ email,
+}: {
+ email: string;
+}): Promise<{ success: boolean; error?: string; data?: Admin }> {
+ const exitingAdmin = await prismadb.admin.findUnique({
+ where: {
+ email: email,
+ },
+ });
+
+ if (!exitingAdmin) {
+ return {
+ success: false,
+ error: 'Admin does not exists',
+ };
+ }
+ const resp = await generateAndSendOTP(email, 'admin');
+
+ if (!resp) {
+ return { success: false, error: 'Error occured in sending otp' };
+ }
+
+ return { success: true };
+}
diff --git a/alimento-nextjs/app/admin/[adminId]/page.tsx b/alimento-nextjs/app/admin/[adminId]/page.tsx
index 4c21631..9231368 100644
--- a/alimento-nextjs/app/admin/[adminId]/page.tsx
+++ b/alimento-nextjs/app/admin/[adminId]/page.tsx
@@ -1,6 +1,6 @@
const AdminPage = () => {
return (
-
hi from admin
+ hiiii
);
}
diff --git a/alimento-nextjs/app/admin/auth/components/login-form.tsx b/alimento-nextjs/app/admin/auth/components/login-form.tsx
index 0dd9209..7e9f80c 100644
--- a/alimento-nextjs/app/admin/auth/components/login-form.tsx
+++ b/alimento-nextjs/app/admin/auth/components/login-form.tsx
@@ -1,15 +1,17 @@
-"use client";
+'use client';
-import * as React from "react";
-import { Button } from "@/components/ui/button";
-import { Input } from "@/components/ui/input";
-import { Label } from "@/components/ui/label";
-import { Spinner } from "@/components/ui/spinner";
-import { cn } from "@/lib/utils";
-import toast, { Toaster } from "react-hot-toast";
+import * as React from 'react';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+import { Label } from '@/components/ui/label';
+import { Spinner } from '@/components/ui/spinner';
+import { OtpForm } from './otp-form';
+import { AdminVerify } from '@/actions/Admin/admin-login';
+import { cn } from '@/lib/utils';
+import toast, { Toaster } from 'react-hot-toast';
interface AdminAuthFormProps extends React.HTMLAttributes {
- authType: "signup" | "login";
+ authType: 'signup' | 'login';
}
export function AdminLoginForm({
@@ -18,52 +20,72 @@ export function AdminLoginForm({
...props
}: AdminAuthFormProps) {
const [isLoading, setIsLoading] = React.useState(false);
- const [email, setEmail] = React.useState("");
+ const [email, setEmail] = React.useState('');
+ const [otpOpen, setOtpOpen] = React.useState(false);
async function onSubmit(event: React.SyntheticEvent) {
event.preventDefault();
setIsLoading(true);
- setIsLoading(false);
+ if (!email) {
+ toast.error('Please enter an email.');
+ setIsLoading(false);
+ return;
+ }
+
+ try {
+ const res = await AdminVerify({ email });
+
+ if (!res.success) {
+ toast.error(res.error || 'Error verifying admin.');
+ setIsLoading(false);
+ return;
+ }
+
+ toast.success('Admin verified! Please enter the OTP.');
+ setOtpOpen(true);
+ } catch (error) {
+ toast.error('Verification failed, please try again.');
+ } finally {
+ setIsLoading(false);
+ }
}
return (
-