How to solve problem with oAuth Zoom in Nextjs?

I am trying to authenicat the user inorder to get data to use to create or update meetings later. but it full of errors. Here I am sending Post request 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>

   )
 }

Hi @Kanwal_Aftab

Thank you for reaching out to the Zoom Developer Forum, I am happy to help here!
Have you tried making this request via Postman and confirm that you are getting the response you are looking for?

You forget to mention what Error are you getting? So it would be helpful to explain the mistake.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.