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
+28 -35
View File
@@ -1,36 +1,32 @@
import { useState } from "react"
import { useRouter } from "next/router"
import { useState } from 'react'
import { useRouter } from 'next/router'
import { signIn } from 'next-auth/react'
export default function SignIn() {
const [username, setUsername] = useState("")
const [password, setPassword] = useState("")
const [error, setError] = useState("")
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
const router = useRouter()
const handleSubmit = async (e) => {
e.preventDefault()
setError("")
setError('')
setLoading(true)
try {
const res = await fetch("/api/auth/signin", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password })
const result = await signIn('credentials', {
redirect: false,
callbackUrl: '/dashboard',
username,
password,
})
const data = await res.json()
if (res.ok && data.ok) {
// Set session cookie
document.cookie = `next-auth.session-token=${data.token}; path=/; SameSite=Lax`
router.push("/dashboard")
} else {
setError(data.error || "Erro ao entrar")
if (result.error) {
setError(result.error)
} else if (result.status === 'ok') {
router.push('/dashboard')
}
} catch (err) {
setError("Erro de conexão")
setError('Authentication error')
} finally {
setLoading(false)
}
@@ -40,45 +36,42 @@ export default function SignIn() {
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
<div className="bg-white p-8 rounded-lg shadow-md w-96">
<h2 className="text-2xl font-bold mb-6">Entrar - 1000Apps</h2>
{error && (
<div className="bg-red-100 text-red-700 p-3 rounded mb-4">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<input
type="text"
placeholder="Nome de usuário"
className="w-full p-2 border rounded"
value={username}
onChange={(e) => setUsername(e.target.value)}
className="w-full p-2 border rounded"
required
/>
<input
type="password"
placeholder="Senha"
className="w-full p-2 border rounded"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full p-2 border rounded"
required
/>
<button
type="submit"
<button
type="submit"
disabled={loading}
className="w-full bg-blue-600 text-white py-2 rounded-lg disabled:opacity-50"
>
{loading ? "Entrando..." : "Entrar"}
{loading ? 'Entrando...' : 'Entrar'}
</button>
</form>
<p className="text-center mt-4 text-sm">
Não tem conta?{" "}
Não tem conta?{' '}
<a href="/signup" className="text-blue-600 hover:underline">
Cadastrar
</a>
</p>
{error && (
<div className="mt-4 bg-red-100 text-red-700 p-3 rounded">
{error}
</div>
)}
</div>
</div>
)