fix: move prisma generate to builder stage, add migration and entrypoint, replace custom login with NextAuth credentials provider

This commit is contained in:
Carlos
2026-07-10 21:56:45 +02:00
parent cef5402cfa
commit 583170efd1
8 changed files with 80 additions and 145 deletions
-54
View File
@@ -1,54 +0,0 @@
import { PrismaClient } from "@prisma/client"
import bcrypt from "bcryptjs"
const prisma = new PrismaClient()
export default async function handler(req, res) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Método não permitido" })
}
const { username, password } = req.body
if (!username || !password) {
return res.status(400).json({ error: "Username e senha são obrigatórios" })
}
try {
const user = await prisma.user.findUnique({
where: { username }
})
if (!user) {
return res.status(401).json({ error: "Usuário não encontrado" })
}
if (!user.password) {
return res.status(401).json({ error: "Senha não configurada" })
}
const isValid = await bcrypt.compare(password, user.password)
if (!isValid) {
return res.status(401).json({ error: "Senha incorreta" })
}
// Create a JWT token manually for the session
const token = require("jsonwebtoken").sign(
{ sub: user.id, email: user.email, name: user.name || user.username },
process.env.NEXTAUTH_SECRET || "test-secret-2x4=",
{ expiresIn: "30d" }
)
return res.status(200).json({
ok: true,
user: { id: user.id, email: user.email, name: user.name || user.username },
token
})
} catch (error) {
console.error("Signin error:", error)
return res.status(500).json({ error: "Erro interno do servidor" })
} finally {
await prisma.$disconnect()
}
}
-53
View File
@@ -1,53 +0,0 @@
import { PrismaClient } from "@prisma/client"
import bcrypt from "bcryptjs"
const prisma = new PrismaClient()
export default async function handler(req, res) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Método não permitido" })
}
const { username, password } = req.body
if (!username || !password) {
return res.status(400).json({ error: "Username e senha são obrigatórios" })
}
if (password.length < 6) {
return res.status(400).json({ error: "Senha deve ter pelo menos 6 caracteres" })
}
try {
// Check if username exists
const existingUser = await prisma.user.findUnique({
where: { username }
})
if (existingUser) {
return res.status(400).json({ error: "Nome de usuário já existe" })
}
// Hash password
const hashedPassword = await bcrypt.hash(password, 12)
// Create user
const user = await prisma.user.create({
data: {
username,
password: hashedPassword,
email: `${username}@1000apps.local`
}
})
return res.status(201).json({
message: "Usuário criado com sucesso",
user: { id: user.id, username: user.username }
})
} catch (error) {
console.error("Signup error:", error)
return res.status(500).json({ error: "Erro interno do servidor" })
} finally {
await prisma.$disconnect()
}
}