'how to solve problem with oAuth Zoom in Nextjs?

I am trying to authenticate the user in order to get data to use to create or update meetings later. but it full of errors. Here I am sending Post Requests in order to get the AccessToken and then get the UserData as props.

export async function getServerSideProps(res){


const oauth = async() => {
     const zoomUserData = [];
       const b = Buffer.from(process.env.ZOOM_API_KEY + ":" + process.env.ZOOM_API_SECRET);

 const zoomRes = await fetch(`https://zoom.us/oauth/token?grant_type=authorization_code&code=${req.body.code}&redirect_uri=${process.env.ZOOM_REDIRECT_URL}`, {
   method: "POST",
   headers: {
     Authorization: `Basic ${b.toString("base64")}`,
   },
 });
 const zoomData = await zoomRes.json();
 const zoomUserRes = await fetch("https://api.zoom.us/v2/users/me", {
   method: "GET",
   headers: {
     Authorization: `Bearer ${zoomData.access_token}`,
   },
 });
 const zoomUserData = await zoomUserRes.json();


 /* 
   Encrypt and store below details to your database:
     zoomUserData.email
     zoomUserData.account_id
     zoomData.access_token
     zoomData.refresh_token
     zoomData.expires_in // convert it to time by adding these seconds to current time
 */



}



return{
     props:{zoomUserData}
   }
 }

and then i am passing the props to a page component like that :

export default function Meeting({zoomUserData}) { 
  const router = useRouter();  
      useEffect(() => {    
         if (router.query.code) { 
             fetch('/connectZoom',
              { method: 'POST',
         headers: {
           'ContType': 'application/json',
         },
         body: JSON.stringify({ code: router.query.code }),
       }).then(() => {
         console.log("success")
       }).catch(() => {
         console.log("No!")    
   });
     }
   }, [router.query.code]);
   console.log(zoomUserData)

   return (

     <a href={`https://zoom.us/oauth/authorize?response_type=code&client_id=${process.env.ZOOM_API_KEY}&redirect_uri=${process.env.ZOOM_REDIRECT_URL}`}>
       Connect Zoom
 </a>

   )
 }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source