discord-oauth2-example icon indicating copy to clipboard operation
discord-oauth2-example copied to clipboard

how to fix Error Code: 500 (AxiosError code 401)

Open natamongkol opened this issue 1 year ago • 2 comments

I try to run but error code 500 in console show

AxiosError {message: 'Request failed with status code 401', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: ClientRequest, …}

how to fix it

natamongkol avatar Apr 06 '23 08:04 natamongkol

Hey nagamongkol, A 401 error indicates invalid authentication credentials. You can try checking the server log for this. This could be due to invalid client (bot) information, such as the client secret.

WhoAmI1000 avatar Apr 06 '23 15:04 WhoAmI1000

Hey, you have to change this part: fetch('https://discord.com/api/oauth2/token', { method: "POST", body: data_1 }).then(response => response.json()).then(data => { axios.get("https://discord.com/api/users/@me", make_config(data.access_token)).then(response => { res.status(200).send(response.data.username); }).catch(err => { console.log(err); res.sendStatus(500); }); });

to: fetch('https://discord.com/api/oauth2/token', { method: "POST", body: data_1 }).then(response => response.json()).then(data => { axios.get("https://discord.com/api/v10/users/@me", make_config(data.access_token)).then(response => { res.status(200).send(response.data.username); }).catch(err => { console.log(err); res.sendStatus(500); }); });

(The difference is this (+ v10): .../api/users/@me --> .../api/v10/users/@me )

TheWuschelGang avatar Jun 18 '24 15:06 TheWuschelGang