WhoAmI1000 / discord-oauth2-example

Example of a Discord OAuth2 Login System
https://circlertech.com/working-with-discord-oauth2
MIT License
27 stars 12 forks source link

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

Open natamongkol opened 1 year ago

natamongkol commented 1 year ago

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

WhoAmI1000 commented 1 year ago

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.

TheWuschelGang commented 2 months ago

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 )