react login api example

  const [isBookingDone, setIsBookingDone] = useState(false); const [isError, setIsError] = useState(false); const [errorMessage, setErrorMessage] = useState(”); const slotBooking = async (slotTiming, bookedDate, userId) => { let config = { url: `http://localhost:3005/api/bookings`, method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, }, data: { ‘slotTiming’: slotTiming, ‘bookedDate’: bookedDate, ‘userId’: userId }, }; await axios(config).then((res) => { loadBookingData(); setIsBookingDone(true); }).catch((e) …

react login api example Read More »

call useEffect Axios api in react

  useEffect(() => { const loadPost = async () => { // Till the data is fetch using API // the Loading page will show. setIsLoading(true); // Await make wait until that // promise settles and return its result const response = await axios.get( `https://jsonplaceholder.typicode.com/posts/${bookingDate}`); // After fetching data stored it in posts state. setBookingData(response.data); …

call useEffect Axios api in react Read More »

create jwt token

  var jwt = require(‘jsonwebtoken’); let user = { email: ‘userDetails.email’, firstName: ‘userDetails.firstName’, lastName: ‘userDetails.lastName’, userType: ‘userDetails.userType’, id: ‘userDetails.id’, } const expiresInSecs = 120; const token = jwt.sign({ data: user }, ‘secret_key’, { expiresIn: 60 * 60 }); console.log(‘ttttttttt’, token)