Authentication using Fetch and react-hook-form

import { useForm } from "react-hook-form";const { register, handleSubmit } = useForm<Credentials>();
<TextField name="email" inputRef={register} </TextField>
import { useForm } from "react-hook-form";<form onSubmit={handleSubmit(onSignIn)}>
import jwtDecode from "jwt-decode";const onSignIn = async ({ email, password }: Credentials) => {    const result = await fetch("/authenticationApi", {      method: "POST",      headers: {        "Content-Type": "application/json",      },      body: JSON.stringify({        username: email,        password,       }),     });    if (result.ok) {       const promiseData = await result.json();       const { jwtToken } = promiseData;       const { "header": decoded } = jwtDecode<Token>(         jwtToken,       );       console.log("Decoded Value of the token" + decoded);     } else {       console.log("Access is not allowed");    } };
const { createProxyMiddleware } = require("http-proxy-middleware");
module.exports = app => {
const proxy = createProxyMiddleware("/authenticationApi", { changeOrigin: true, autoRewrite: true, target: "http://localhost:portnumber", }); app.use(proxy);};

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store