feat: replace custom login/signup with NextAuth credentials provider, add signup page using Prisma, update NextAuth config to JWT strategy
This commit is contained in:
+18
-20
@@ -12,28 +12,26 @@ export default function SignUp() {
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault()
|
||||
setError("")
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
setError("Senhas não coincidem")
|
||||
return
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
setError("Senha deve ter pelo menos 6 caracteres")
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true)
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/auth/signup", {
|
||||
if (password !== confirmPassword) {
|
||||
setError("Senhas não coincidem")
|
||||
return
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
setError("Senha deve ter pelo menos 6 caracteres")
|
||||
return
|
||||
}
|
||||
|
||||
const res = await fetch("/api/auth/register", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password })
|
||||
})
|
||||
|
||||
|
||||
const data = await res.json()
|
||||
|
||||
|
||||
if (res.ok) {
|
||||
router.push("/signin")
|
||||
} else {
|
||||
@@ -52,7 +50,7 @@ export default function SignUp() {
|
||||
<h2 className="text-2xl font-bold mb-6">Cadastrar - 1000Apps</h2>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-100 text-red-700 p-3 rounded mb-4">
|
||||
<div className="mb-4 bg-red-100 text-red-700 p-3 rounded">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
@@ -61,30 +59,30 @@ export default function SignUp() {
|
||||
<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
|
||||
minLength={6}
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Confirmar senha"
|
||||
className="w-full p-2 border rounded"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
className="w-full p-2 border rounded"
|
||||
required
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full bg-green-600 text-white py-2 rounded-lg disabled:opacity-50"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user