Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
How can I login using usermail and userpassword from my API in React?

I want to login using email and password from API. If the email and password in the API are correct, log in. When I use const adminUser it logs in. But I don't know how to login using the API

If the email and password entered by the user are the same as the email and password in my API, I want the LoginPage page to open.

import React, { useState } from "react";
import LoginForm from "./LoginForm";

export default function LoginApp() {

  const adminUser = {
    email: "admin@admin.com",
    password: "123",
  };

  const [user, setUser] = useState({ email: "", password: "" });
  const [error, setError] = useState("");

  const Login = (details) => {
    console.log(details);

    if (details.email === adminUser.email && details.password === adminUser.password) {
        console.log("Logged in")
        setUser({
            email:details.email,
            password:details.password
        })
    }else{
        console.log()
        setError("Details do not match")

    }

  };

  const Logout = () => {
    setUser({
        email:"", password:""
    })
  };

  return (
    <div className="LoginApp">
      {user.email !== "" ? (
        <div className="welcome">
          <h2>
            Welcome, <span>{user.email}</span>
          </h2>
          <button onClick={Logout}>Logout</button>
        </div>
      ) : (
        <LoginForm Login={Login} error={error}/>
      )}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!