ok figured it out

This commit is contained in:
oat 2020-10-12 05:10:15 +03:00
parent df6c1545af
commit 96facbf2e2
Signed by: oat
GPG key ID: DD83A9617A252385

View file

@ -6,10 +6,9 @@ const API_ENDPOINT = 'https://discord.com/api/v6';
const axios = require('axios').default;
export function run(app) {
const logger = app.get('logger');
app.get('/discordauth', async (req, res) => {
const code = req.query.code;
const url = `http://${req.headers.host}/discordauth`;
if (code) {
try {
@ -18,7 +17,7 @@ export function run(app) {
client_secret: process.env.DISCORD_OAUTH_CLIENTSECRET,
grant_type: 'authorization_code',
code: code,
redirect_uri: 'http://localhost:8080/discordauth',
redirect_uri: url,
scope: 'identify'
});
@ -60,10 +59,8 @@ export function run(app) {
} catch(err) {
res.send(`whoooops<br>${err}`);
console.error(err);
logger.error(err);
}
} else {
const url = `http://${req.headers.host}/discordauth`;
res.send(`<a href="https://discord.com/api/oauth2/authorize?client_id=${process.env.DISCORD_OAUTH_CLIENTID}&redirect_uri=${encodeURI(url)}&response_type=code&scope=identify">Click here!!</a>`);
}
});