Error
Something went wrong.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
|
|
||||||
import { handlers } from '@/auth';
|
import { handlers } from '@/auth';
|
||||||
|
|
||||||
export const { GET, POST } = handlers;
|
export const { GET, POST } = handlers;
|
||||||
|
|
||||||
export const runtime = "nodejs";
|
|
||||||
|
|||||||
+2
-7
@@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
import NextAuth from 'next-auth';
|
import NextAuth from 'next-auth';
|
||||||
import { authConfig } from './auth.config';
|
import { authConfig } from './auth.config';
|
||||||
import Credentials from 'next-auth/providers/credentials';
|
import Credentials from 'next-auth/providers/credentials';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import db from '@/lib/db';
|
import { getUserByEmail } from '@/lib/actions/user';
|
||||||
|
|
||||||
export const { handlers, auth, signIn, signOut } = NextAuth({
|
export const { handlers, auth, signIn, signOut } = NextAuth({
|
||||||
...authConfig,
|
...authConfig,
|
||||||
@@ -17,9 +16,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
|
|||||||
if (parsedCredentials.success) {
|
if (parsedCredentials.success) {
|
||||||
const { email, password } = parsedCredentials.data;
|
const { email, password } = parsedCredentials.data;
|
||||||
|
|
||||||
const userStmt = db.prepare('SELECT * FROM users WHERE email = ?');
|
const user = await getUserByEmail(email);
|
||||||
const user = userStmt.get(email) as any;
|
|
||||||
|
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
|
|
||||||
// WARNING: Storing passwords in plaintext is insecure.
|
// WARNING: Storing passwords in plaintext is insecure.
|
||||||
@@ -39,5 +36,3 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
|
|||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
export const runtime = "nodejs";
|
|
||||||
|
|||||||
+19
-1
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
@@ -14,6 +13,25 @@ const formSchema = z.object({
|
|||||||
|
|
||||||
type UserFormValues = z.infer<typeof formSchema>;
|
type UserFormValues = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
|
type User = {
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
email: string;
|
||||||
|
password?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getUserByEmail(email: string): Promise<User | null> {
|
||||||
|
try {
|
||||||
|
const stmt = db.prepare('SELECT id, name, email, password FROM users WHERE email = ?');
|
||||||
|
const user = stmt.get(email) as User | undefined;
|
||||||
|
return user || null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to get user by email:', error);
|
||||||
|
throw new Error('Database error while fetching user.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the currently logged-in user from the session.
|
* Gets the currently logged-in user from the session.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user