Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

login_page-jwt-auth-using-react-and-flask

function Login() {
  const [username, setUsername] = useState('')
  const [password, setPassword] = useState('')

  const onSubmitClick = (e)=>{
    e.preventDefault()
    console.log("You pressed login")
    let opts = {
      'username': username,
      'password': password
    }
    console.log(opts)
    fetch('/api/login', {
      method: 'post',
      body: JSON.stringify(opts)
    }).then(r => r.json())
      .then(token => {
        if (token.access_token){
          console.log(token)          
        }
        else {
          console.log("Please type in correct username/password")
        }
      })
  }

  const handleUsernameChange = (e) => {
    setUsername(e.target.value)
  }

  const handlePasswordChange = (e) => {
    setPassword(e.target.value)
  }

  return (
    <div>
      <h2>Login</h2>
      <form action="#">
        <div>
          <input type="text" 
            placeholder="Username" 
            onChange={handleUsernameChange}
            value={username} 
          />
        </div>
        <div>
          <input
            type="password"
            placeholder="Password"
            onChange={handlePasswordChange}
            value={password}
          />
        </div>
        <button onClick={onSubmitClick} type="submit">
          Login Now
        </button>
      </form>
    </div>
  )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: top 50 mcq que in javascript 
Javascript :: how to poll every n seconds in react js 
Javascript :: concat not working javascript 
Javascript :: what is fn extend 
Javascript :: cloning an element 
Javascript :: delete head array js 
Javascript :: react router v6 wrapped routes in separate files 
Javascript :: formulaire sauvegarde local storage jquery 
Javascript :: getComments 
Javascript :: create multidimensional array with foreach javascript 
Javascript :: GLTF position three.js 
Javascript :: javascript find in array cannot read property of undefined 
Javascript :: toggle value change inline angular 
Javascript :: how to return the entire array x+1 in javascript 
Javascript :: How to Compare Strings Using localeCompare 
Javascript :: odoo js reload widget 
Javascript :: how to use session with cookie js nodejs 
Javascript :: _.extend can be used to attach functions to a prototype like this 
Javascript :: When defined as a method of an object, in a regular function this refers to the object 
Javascript :: Include Id In Backbone 
Javascript :: find result using type: mongoose.Schema.ObjectId, 
Javascript :: Colored tab in react Js MUI 
Javascript :: js calculate hours between two times 
Javascript :: port for sqlexpress not found in desktop node.js 
Javascript :: how to use script tag in javascript 
Javascript :: convert h2 to h1 jQuery 
Javascript :: express docs 
Javascript :: jquery datatable searchpane pagination not working 
Javascript :: Using conditional tailwind classes for twin.macro 
Javascript :: onclick a hyperlink and display the id of clicked hyperlink js 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =