Skip to content

Instantly share code, notes, and snippets.

@orels1
Created May 16, 2017 21:33
Show Gist options
  • Save orels1/3495352b88bd60299181e3252db15f76 to your computer and use it in GitHub Desktop.
Save orels1/3495352b88bd60299181e3252db15f76 to your computer and use it in GitHub Desktop.
router.get('/callback', catchAsync(async (req, res) => {
if (!req.query.code) throw new Error('NoCodeProvided');
const code = req.query.code;
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`);
const response = await fetch(`https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=${code}&redirect_uri=${redirect}`,
{
method: 'POST',
headers: {
Authorization: `Basic ${creds}`,
},
});
const json = await response.json();
res.redirect(`/?token=${json.access_token}`);
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment