
I am a full-stack web developer that enjoys coding in Laravel and React.
Search for a command to run...

I am a full-stack web developer that enjoys coding in Laravel and React.
No comments yet. Be the first to comment.
In this series I'll discuss how I solved problems with frontend technologies like React, Vue, Next, Nuxt, Gatsby, etc. in the style of tutorials.
Here's what I learned so far using it in Gatsby
Switching stacks

If you don't know what Twin Macro is, check it out! It's a great library that blends Tailwind CSS and Styled Component systems, like Emotion. I love using Twin because it lets me use Tailwind while separating my styling from my markup and methods. If...

Many developers know that full-stack apps with a Vue frontend can be quickly spun up with Laravel Jetstream. What many don’t know is that recently, the Laravel team made it easy to make an Inertia app with Laravel Breeze. In this article, we'll make ...

Extending the Rule Object with a DateTime Trait

Using Custom Console Commands

No reason for a long intro paragraph. Here is the first part for Zoom OAuth with NuxtJS, if you haven't seen it yet. Let's get to work!
Preliminaries:
fetch is not automatically available in our serverMiddleware (don't ask, I dunno). Hence, we'll need to import the node-fetch library into our project like so: const fetch = require('node-fetch').First Steps:
const fetch = require('node-fetch')
const handler = async (req, res) => {
//
}
export default handler
The Work Begins: Our serverMiddleware will help us get the Access Token which will be used to get user data.
try...catch blocks because they make error and response handling easier and cleaner. So let's create one inside our handler.const handler = async (req,res) => {
try {
//
}
catch(e){
console.log(e)
}
}
grant_type, code, and redirect_uri.grant_type, according to the docs, is 'authorization_code'.code, we'll need to catch the value for the code param that we got from the client-side.redirect_uri is the same base URL that we have in our .env file.code, we'll use the URL interface that is also made available in Node. The URL interface has a property called searchParams that has all query params in an object, and we can use the get method to retrieve its value. To make use of the URL interface, we'll need to make an absolute URL, since the URL we get from the client is only partial.try {
const url = new URL(req.url, `https://${req.headers.host}`)
const zoomUrl = new URL('https://zoom.us/oauth/token')
zoomUrl.searchParams.set('grant_type', 'authorization_code')
zoomUrl.searchParams.set('code', url.searchParams.get('code'))
zoomUrl.searchParams.set('redirect_uri', process.env.NUXT_ENV_BASE_URL)
}
The Work Continues: Zoom has a strange demand that we use a special code in our header to make our POST request. This code is special because, in pseudocode, it would look something like this: base64(CLIENT_ID:CLIENT_SECRET).
const data = process.env.NUXT_ENV_ZOOM_CLIENT_ID + ':' + process.env.NUXT_ENV_ZOOM_CLIENT_SECRET
const newData = Buffer.from(data, 'utf8')
const b64string = newData.toString('base64')
fetch. If we await our JSON response, we should get back an object with our access token.const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + b64string
}
}
const response = await fetch(zoomUrl, options)
const json = await response.json()
The Work Ends:
fetch, but using the GET method this time. if (json.access_token){
const preUser = await fetch('https://api.zoom.us/v2/users', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + json.access_token
}
})
const user = await preUser.json()
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(user))
}
else {
throw new Error('Something went wrong!')
}
getZoomUser. In the last line of that method, just log user to the console, open your browser and you'll see what you get.Conclusion: