discord-token-generator icon indicating copy to clipboard operation
discord-token-generator copied to clipboard

token undefined

Open phildev4 opened this issue 4 years ago • 15 comments

phildev4 avatar Dec 02 '20 16:12 phildev4

same here

lucasyrsdr avatar Jan 04 '21 01:01 lucasyrsdr

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!

alaninnovates avatar Feb 24 '21 23:02 alaninnovates

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

yakirifrah avatar Jun 10 '21 09:06 yakirifrah

@alanlichen I managed on my own thanks anyway 😀

yakirifrah avatar Jun 10 '21 09:06 yakirifrah

Ok :)

alaninnovates avatar Jun 10 '21 19:06 alaninnovates

catchAsyncErrors is not defined

lasse-lenting avatar Jul 09 '21 19:07 lasse-lenting

You must define it, the blog has the function there

alaninnovates avatar Jul 09 '21 22:07 alaninnovates

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"

Voxioo avatar Jul 22 '21 13:07 Voxioo

URLSearchParams is undefined. How to resolve this?

reiz avatar Sep 26 '21 15:09 reiz

URLSearchParams is undefined. How to resolve this?

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

reiz avatar Sep 26 '21 15:09 reiz

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

alaninnovates avatar Sep 26 '21 21:09 alaninnovates

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.

reiz avatar Sep 30 '21 17:09 reiz

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

OverpoweredCoding avatar Dec 04 '21 03:12 OverpoweredCoding

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

alaninnovates avatar Dec 04 '21 04:12 alaninnovates

Now I'm getting the same thing as @Voxioo

OverpoweredCoding avatar Dec 04 '21 19:12 OverpoweredCoding