selvi jp

selvi jp

  • NA
  • 323
  • 69.7k

Login with web API in React js

May 28 2021 5:14 AM
This is my login form i want to auth login with web api url.i am done web api login,the
only think I want how can i call web api here
  1. import React, { useState } from 'react';  
  2. import {useFormik, yupToFormErrors} from 'formik';  
  3. import * as yup from 'yup';  
  4. import 'bootstrap/dist/css/bootstrap.min.css';  
  5. import 'font-awesome/css/font-awesome.min.css';  
  6. import showPwdImg from './show-password.svg';  
  7. import hidePwdImg from './hide-password.svg';  
  8. const Login =() =>{  
  9.   const [isRevealPwd, setIsRevealPwd] = useState(false);  
  10. const formik = useFormik({  
  11. initialValues:{  
  12. name:"",  
  13. password:""   
  14.    
  15. },  
  16. validationSchema:yup.object({  
  17. name:yup.string()              
  18. .required('UserName is required')  
  19. .strict()  
  20. .trim()  
  21. .min(5)   
  22. .max(15,'Maximum 15 character') ,  
  23.    
  24. password:yup.string()  
  25. .required('Password is required')  
  26. .min(6)   
  27. .max(15,'Maximum 10 character')     
  28. }),  
  29.   
  30. onSubmit:(userInputData)=>{  
  31. console.log(userInputData);  
  32. }  
  33. })   
  34. return(  
  35.      
  36. <div className="container mt-4">  
  37. <div>  
  38.   
  39.    <form autoComplete="off" onSubmit={formik.handleSubmit}>  
  40.       <div className="form-group">  
  41.       <header className="head-form">  
  42.             <h2>Log In</h2>  
  43.              
  44.          </header>  
  45.            
  46.          <div className="input-icons">  
  47.          <i className="fa fa-user icon"></i>  
  48.          <input className="form-control" placeholder="Username" type="text" name="name" id="login"onChange={formik.handleChange} value={formik.values.name}/>  
  49.          </div>  
  50.          {formik.errors.name ?  
  51.          <div className="text-danger">{formik.errors.name}</div>  
  52.          :null  
  53.          }  
  54.       </div>  
  55.         
  56.       <div className="form-group ">  
  57.          <div className="input-icons">  
  58.          <i className="fa fa-key"></i>  
  59.          <input className="form-control" placeholder="Password" id="loginpwd"  name="password" onChange={formik.handleChange}  type={isRevealPwd ? "text" : "password"}  
  60.           value={formik.values.password}  
  61.          />  
  62.          <img  
  63.           title={isRevealPwd ? "Show password" : "Hide password"}  
  64.           src={isRevealPwd ? showPwdImg : hidePwdImg}  
  65.           onClick={() => setIsRevealPwd(prevState => !prevState)}  
  66.         />  
  67.           
  68.          {formik.errors.password ?  
  69.          <div className="text-danger">{formik.errors.password}</div>  
  70.          :null  
  71.          }  
  72.           </div>  
  73.       </div>  
  74.       <button className="log-in" type="text">Submit</button>  
  75.    </form>  
  76. </div>  
  77.   
  78. </div>  
  79. )  
  80. }  
  81. export default Login;