Code Monkey home page Code Monkey logo

Comments (15)

lucasyrsdr avatar lucasyrsdr commented on June 24, 2024

same here

from discord-token-generator.

alaninnovates avatar alaninnovates commented on June 24, 2024

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!

from discord-token-generator.

yakirifrah avatar yakirifrah commented on June 24, 2024

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

from discord-token-generator.

yakirifrah avatar yakirifrah commented on June 24, 2024

@alanlichen I managed on my own thanks anyway 😀

from discord-token-generator.

alaninnovates avatar alaninnovates commented on June 24, 2024

Ok :)

from discord-token-generator.

lasse-lenting avatar lasse-lenting commented on June 24, 2024

catchAsyncErrors is not defined

from discord-token-generator.

alaninnovates avatar alaninnovates commented on June 24, 2024

You must define it, the blog has the function there

from discord-token-generator.

Voxioo avatar Voxioo commented on June 24, 2024

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"

from discord-token-generator.

reiz avatar reiz commented on June 24, 2024

URLSearchParams is undefined. How to resolve this?

from discord-token-generator.

reiz avatar reiz commented on June 24, 2024

URLSearchParams is undefined. How to resolve this?

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

from discord-token-generator.

alaninnovates avatar alaninnovates commented on June 24, 2024

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

from discord-token-generator.

reiz avatar reiz commented on June 24, 2024

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.

from discord-token-generator.

OverpoweredCoding avatar OverpoweredCoding commented on June 24, 2024

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

from discord-token-generator.

alaninnovates avatar alaninnovates commented on June 24, 2024

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

from discord-token-generator.

OverpoweredCoding avatar OverpoweredCoding commented on June 24, 2024

Now I'm getting the same thing as @Voxioo

from discord-token-generator.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.