#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Authentication

Showing Feedback to the User

Showing feedback to the user means telling people what is happening while they sign up or log in: that a request is running, that it worked, or exactly why it failed. Authentication forms talk to a server, so there is always a short wait and a real chance of errors. Without feedback, users click again, refresh, or give up.

The three states every auth request goes through

Think of each submit as moving through a small set of states. Modelling them explicitly makes the UI easier to reason about.

StateWhat the user should see
IdleThe normal form with an enabled submit button.
SubmittingA disabled button with text like "Creating account..." or a spinner.
ErrorA clear message near the form, with the typed values still in place.
SuccessA confirmation or an immediate redirect to the next page.

A single status string in state is often cleaner than several separate booleans, because it cannot be "loading" and "error" at the same time by accident.

Turning server errors into readable messages

Auth backends usually return an error code or message in the response body. Those raw codes, such as EMAIL_EXISTS or WEAK_PASSWORD, are not friendly. Map them to plain sentences before displaying them.

const messages = {
  EMAIL_EXISTS: 'An account with this email already exists.',
  WEAK_PASSWORD: 'Please choose a password with at least 8 characters.',
  INVALID_CREDENTIALS: 'Email or password is incorrect.',
};

function SignupForm() {
  const [status, setStatus] = useState('idle');
  const [message, setMessage] = useState('');

  async function submit(values) {
    setStatus('submitting');
    try {
      const res = await fetch('/api/signup', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(values),
      });
      const data = await res.json();
      if (!res.ok) {
        setMessage(messages[data.code] ?? 'Something went wrong. Try again.');
        setStatus('error');
        return;
      }
      setStatus('success');
    } catch {
      setMessage('Could not reach the server. Check your connection.');
      setStatus('error');
    }
  }

  return (
    <>
      {status === 'error' && <p role="alert">{message}</p>}
      {status === 'success' && <p>Account created. You can log in now.</p>}
      {/* form fields, button disabled when status === 'submitting' */}
    </>
  );
}

The fallback message covers codes you did not plan for, and the catch block handles the case where the request never reached the server at all.

Making feedback accessible

Screen reader users need to hear the message too. Adding role="alert" to the error element asks assistive technology to announce it as soon as it appears. Keep the message near the button or the field it relates to, and do not rely on colour alone; a red border without text tells a colour-blind user nothing.

A pitfall: clearing the form on error

A frustrating pattern is resetting every input when the server rejects the request. The user then retypes their name and email just to fix one password. Keep the values, clear only the password if you must, and put focus back on the field that needs attention. Also clear the old error message when a new submit starts, otherwise a stale error stays visible during the next attempt.

Where to show what

  • Field-level problems, like an invalid email format, belong next to that field and can be checked before sending.
  • Server-level problems, like a taken email, belong in one message above the button.
  • Success can be a short message, a toast, or simply navigating to the dashboard.

For very fast responses, a spinner that flashes for a fraction of a second can feel glitchy. Changing the button text is calmer than swapping the whole form for a loader, and it keeps the layout from jumping around while the request runs.

Good feedback answers one question at every moment: "What is happening, and what should I do next?" If your form always answers that, users trust it.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course