Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token undefined #11

Open
phildev4 opened this issue Dec 2, 2020 · 15 comments
Open

token undefined #11

phildev4 opened this issue Dec 2, 2020 · 15 comments

Comments

@phildev4
Copy link

phildev4 commented Dec 2, 2020

No description provided.

@lucasyrsdr
Copy link

same here

@alaninnovates
Copy link

alaninnovates commented Feb 24, 2021

Change it to this since discord changed their API.

const redirUri = 'http://localhost:[port]/api/discord/callback';
router.get(
	'/callback',
	catchAsyncErrors(async (req, res) => {
		if (!req.query.code) throw new Error('NoCodeProvided');
		const code = req.query.code;
		const creds = btoa(`${clientId}:${clientSecret}`);
		const data = {
			grant_type: 'authorization_code',
			client_id: clientId,
			client_secret: clientSecret,
			code,
			redirect_uri: redirUri,
			scope: 'identify',
		};
		const response = await fetch(
			`https://discord.com/api/oauth2/token`,
			{
				method: 'POST',
				headers: {
					Authorization: `Basic ${creds}`,
					'Content-type': `application/x-www-form-urlencoded`,
				},
				body: new URLSearchParams(data),
			},
		);
		const json = await response.json();
		console.log(json);
		res.redirect(`/?token=${json.access_token}`);
	}),
);

If you don't understand this, ask!

This was referenced Feb 24, 2021
@yakirifrah
Copy link

@alanlichen I'm get error: 'invalid_client' , i'm glad that you help me with that

@yakirifrah
Copy link

@alanlichen I managed on my own thanks anyway 😀

@alaninnovates
Copy link

Ok :)

@lasse-lenting
Copy link

catchAsyncErrors is not defined

@alaninnovates
Copy link

You must define it, the blog has the function there

@Voxioo
Copy link

Voxioo commented Jul 22, 2021

You must define it, the blog has the function there

defined it, it tells me "Router.use() requires a middleware function but got a Object"

@reiz
Copy link

reiz commented Sep 26, 2021

URLSearchParams is undefined. How to resolve this?

@reiz
Copy link

reiz commented Sep 26, 2021

URLSearchParams is undefined. How to resolve this?

const { URLSearchParams } = require('url');

@alaninnovates
Copy link

alaninnovates commented Sep 26, 2021

URLSearchParams is undefined. How to resolve this?

const { URLSearchParams } = require('url');

@reiz Hello! If you need to require the native URL library in order to use URLSearchParams, I believe that you should need to upgrade your node version. Anything above node v10 should have the library's exported methods defined within the global context. Refer to this for a list of global objects: https://nodejs.org/api/globals.html

@reiz
Copy link

reiz commented Sep 30, 2021

URLSearchParams is undefined. How to resolve this?

const { URLSearchParams } = require('url');

@reiz Hello! If you need to require the native URL library in order to use URLSearchParams, I believe that you should need to upgrade your node version. Anything above node v10 should have the library's exported methods defined within the global context. Refer to this for a list of global objects: https://nodejs.org/api/globals.html

I'm running on v16.6.1. But somehow the URLSearchParams was undefined. After the require it worked perfectly.

@OverpoweredCoding
Copy link

catchAsyncErrors is not defined. Defined it but it's still not working.

@alaninnovates
Copy link

Make sure you are importing it at the top of your file.

@OverpoweredCoding
Copy link

Now I'm getting the same thing as @Voxioo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants