The npm install command failed in my project. Analyze the following er

This commit is contained in:
Leon Serfaty G
2025-09-01 06:34:12 +00:00
parent b76754d151
commit a61b22689f
12 changed files with 342 additions and 117 deletions
+10 -7
View File
@@ -1,7 +1,5 @@
"use client"
import * as React from "react";
import { auth, signOut } from "@/auth"
import Link from 'next/link';
import {
Sidebar,
@@ -13,8 +11,6 @@ import {
SidebarContent,
SidebarInset,
SidebarProvider,
SidebarTrigger,
useSidebar,
} from "@/components/ui/sidebar"
import {
Home,
@@ -29,14 +25,21 @@ import {
Workflow
} from "lucide-react"
import { Button } from "@/components/ui/button";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { logout } from "@/lib/actions/auth";
function AdminLayout({
async function AdminLayout({
children,
}: {
children: React.ReactNode
}) {
const session = await auth()
if (!session) {
// This should be handled by middleware, but as a fallback
const { redirect } = await import("next/navigation")
redirect("/login")
}
return (
<SidebarProvider>
<Sidebar>
+8
View File
@@ -0,0 +1,8 @@
import NextAuth from 'next-auth';
import { authConfig } from '@/auth.config';
export const { handlers, auth, signIn, signOut } = NextAuth(authConfig);
export const GET = handlers.GET;
export const POST = handlers.POST;
+28 -55
View File
@@ -1,13 +1,10 @@
'use client';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';
import { useActionState } from 'react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { useToast } from '@/hooks/use-toast';
import {
Card,
CardContent,
@@ -16,48 +13,23 @@ import {
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { useRouter } from 'next/navigation';
import { login } from '@/lib/actions/auth';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { AlertCircle } from 'lucide-react';
const loginSchema = z.object({
email: z.string().email({ message: 'Invalid email address.' }),
password: z.string().min(1, { message: 'Password is required.' }),
});
function SubmitButton() {
// This component will be updated by useFormStatus in a real app,
// but for now, we just show a static text.
return (
<Button type="submit" className="w-full">
Sign In
</Button>
);
}
type LoginFormValues = z.infer<typeof loginSchema>;
export default function LoginPage() {
const router = useRouter();
const { toast } = useToast();
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm<LoginFormValues>({
resolver: zodResolver(loginSchema),
});
const onSubmit = async (data: LoginFormValues) => {
try {
const result = await login(data);
if (result.success) {
toast({
title: 'Login Successful',
description: 'Redirecting to your dashboard...',
});
router.push('/admin');
} else {
throw new Error(result.message);
}
} catch (error: any) {
toast({
variant: 'destructive',
title: 'Login Failed',
description: error.message || 'An unexpected error occurred.',
});
}
};
const [state, formAction] = useActionState(login, undefined);
return (
<main className="flex min-h-screen flex-col items-center justify-center bg-background p-8">
@@ -71,36 +43,37 @@ export default function LoginPage() {
</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<form action={formAction} className="space-y-4">
{state?.message && (
<Alert variant="destructive">
<AlertCircle className="h-4 w-4" />
<AlertTitle>Error</AlertTitle>
<AlertDescription>{state.message}</AlertDescription>
</Alert>
)}
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
name="email"
type="email"
placeholder="admin@example.com"
{...register('email')}
defaultValue="admin@example.com"
required
/>
{errors.email && (
<p className="text-sm text-destructive">{errors.email.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<Input
id="password"
name="password"
type="password"
placeholder="password"
{...register('password')}
defaultValue="password"
required
/>
{errors.password && (
<p className="text-sm text-destructive">
{errors.password.message}
</p>
)}
</div>
<Button type="submit" className="w-full" disabled={isSubmitting}>
{isSubmitting ? 'Signing In...' : 'Sign In'}
</Button>
<SubmitButton />
</form>
</CardContent>
<CardFooter>