Brijesh's Git Server — argus-web @ 5a0714cb3aaa37575c5d632988d27f8cbf0e2c89

Web Ul for argus

fix: registration redirect
Brijesh Wawdhane ops@brijesh.dev
Sat, 14 Dec 2024 03:24:01 +0530
commit

5a0714cb3aaa37575c5d632988d27f8cbf0e2c89

parent

c02beda1900bfabbff84bdf336bb6120523f3250

2 files changed, 8 insertions(+), 5 deletions(-)

jump to
M src/app/actions/auth.jssrc/app/actions/auth.js

@@ -1,7 +1,5 @@

"use server"; -import { redirect } from "next/navigation"; - export async function login(formData) { try { const response = await fetch("http://localhost:8080/auth/login", {

@@ -43,11 +41,13 @@ }),

}); if (!response.ok) { + const errorText = await response.text(); throw new Error("Registration failed"); } - redirect("/login"); + const data = await response.json(); + return { success: true, data }; } catch (error) { - return { success: false, error: "Registration failed" }; + return { success: false, error: "Registration failed " + error }; } }
M src/components/auth/RegisterForm.jssrc/components/auth/RegisterForm.js

@@ -1,6 +1,7 @@

"use client"; import { useRef, useState } from "react"; +import { useRouter } from "next/navigation"; import Input from "../shared/Input"; import Button from "../shared/Button"; import { register } from "@/app/actions/auth";

@@ -10,6 +11,7 @@ const [error, setError] = useState("");

const [isSubmitting, setIsSubmitting] = useState(false); const formRef = useRef(); const passwordRef = useRef(); + const router = useRouter(); async function handleSubmit(formData) { setIsSubmitting(true);

@@ -26,6 +28,8 @@ const result = await register(formData);

if (!result?.success && result?.error) { setError(result.error); + } else { + router.push("/login"); } setIsSubmitting(false);

@@ -47,7 +51,6 @@ label="Email"

name="email" type="email" required - pattern="[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i" error={error} />