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

445
Views
"[jwt_auth] empty_username" error with React JS - Token - Wordpress - login

I am working on login with React JS and wordpress with the plugin JWT Authentication for WP REST API. I would like to get token but I have a problem

The code is here:

//...
function Login() {

    const[username, setUsername] = useState("")
    
    const[password, setPassword] = useState("")

    const access = async () => {
        
        const response = await fetch(`http://wp-playground.test/wp-json/jwt-auth/v1/token`, {
            method: 'POST', 
            header: {
                'Content-Type' : 'application/json',
            },
            body : JSON.stringify({
                username: username,
                password: password
            })
        })
        const data = await response.json()
        console.log(data)
        setUsername("")
        setPassword("")
    }

    return (
        <div>
            <h2>Login</h2>
            <label>Username: </label><input value={username} onChange={(e) => setUsername(e.target.value)}/><br/><br/>
            <label>Password: </label><input type="password" value={password} onChange={(e) => setPassword(e.target.value)}/><br/><br/>
            <button onClick={access}>Login</button>
        </div>
    )

and I get like this:

{
    code: "[jwt_auth] empty_username"
    data: {
        status: 403
    }
    message: "<strong>Error</strong>: The username field is empty."
}

Thanks for your attention!

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!