Now I cant login with the changed credentials leon@serfaty.co

This commit is contained in:
Leon Serfaty G
2025-07-18 03:04:53 +00:00
parent 27f2439fa5
commit 4b33b2dd24
2 changed files with 39 additions and 6 deletions
+5 -6
View File
@@ -17,6 +17,7 @@ import {
CardTitle, CardTitle,
} from '@/components/ui/card'; } from '@/components/ui/card';
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';
import { login } from '@/lib/actions/auth';
const loginSchema = z.object({ const loginSchema = z.object({
email: z.string().email({ message: 'Invalid email address.' }), email: z.string().email({ message: 'Invalid email address.' }),
@@ -38,18 +39,16 @@ export default function LoginPage() {
const onSubmit = async (data: LoginFormValues) => { const onSubmit = async (data: LoginFormValues) => {
try { try {
// This is a mock login. In a real app, you'd call an authentication service. const result = await login(data);
console.log('Attempting to log in with:', data.email);
await new Promise(resolve => setTimeout(resolve, 1000));
if (data.email === 'admin@example.com' && data.password === 'password') { if (result.success) {
toast({ toast({
title: 'Login Successful', title: 'Login Successful',
description: 'Redirecting to your dashboard...', description: 'Redirecting to your dashboard...',
}); });
router.push('/admin'); router.push('/admin');
} else { } else {
throw new Error('Invalid email or password.'); throw new Error(result.message);
} }
} catch (error: any) { } catch (error: any) {
toast({ toast({
@@ -105,7 +104,7 @@ export default function LoginPage() {
</form> </form>
</CardContent> </CardContent>
<CardFooter> <CardFooter>
<p className="text-xs text-center w-full text-muted-foreground">Use admin@example.com and 'password' to sign in.</p> <p className="text-xs text-center w-full text-muted-foreground">Use your updated credentials to sign in.</p>
</CardFooter> </CardFooter>
</Card> </Card>
</main> </main>
+34
View File
@@ -2,6 +2,40 @@
'use server'; 'use server';
import { redirect } from 'next/navigation'; import { redirect } from 'next/navigation';
import { z } from 'zod';
import db from '@/lib/db';
const loginSchema = z.object({
email: z.string().email(),
password: z.string(),
});
export async function login(data: z.infer<typeof loginSchema>): Promise<{ success: boolean, message: string }> {
const validatedFields = loginSchema.safeParse(data);
if (!validatedFields.success) {
return { success: false, message: 'Invalid fields.' };
}
const { email, password } = validatedFields.data;
try {
const stmt = db.prepare('SELECT * FROM users WHERE email = ? AND password = ?');
const user = stmt.get(email, password);
if (user) {
// In a real app, you would set a session cookie here.
// For this simulated login, we'll just return success.
return { success: true, message: 'Login successful.' };
} else {
return { success: false, message: 'Invalid email or password.' };
}
} catch (error) {
console.error('Login error:', error);
return { success: false, message: 'An internal error occurred.' };
}
}
export async function logout() { export async function logout() {
// In a real app with authentication, this would handle signing out the user. // In a real app with authentication, this would handle signing out the user.