Now I cant login with the changed credentials leon@serfaty.co
This commit is contained in:
@@ -2,6 +2,40 @@
|
||||
'use server';
|
||||
|
||||
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() {
|
||||
// In a real app with authentication, this would handle signing out the user.
|
||||
|
||||
Reference in New Issue
Block a user