ok figured it out
This commit is contained in:
parent
df6c1545af
commit
96facbf2e2
1 changed files with 2 additions and 5 deletions
|
@ -6,10 +6,9 @@ const API_ENDPOINT = 'https://discord.com/api/v6';
|
||||||
const axios = require('axios').default;
|
const axios = require('axios').default;
|
||||||
|
|
||||||
export function run(app) {
|
export function run(app) {
|
||||||
const logger = app.get('logger');
|
|
||||||
|
|
||||||
app.get('/discordauth', async (req, res) => {
|
app.get('/discordauth', async (req, res) => {
|
||||||
const code = req.query.code;
|
const code = req.query.code;
|
||||||
|
const url = `http://${req.headers.host}/discordauth`;
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
try {
|
try {
|
||||||
|
@ -18,7 +17,7 @@ export function run(app) {
|
||||||
client_secret: process.env.DISCORD_OAUTH_CLIENTSECRET,
|
client_secret: process.env.DISCORD_OAUTH_CLIENTSECRET,
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
code: code,
|
code: code,
|
||||||
redirect_uri: 'http://localhost:8080/discordauth',
|
redirect_uri: url,
|
||||||
scope: 'identify'
|
scope: 'identify'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -60,10 +59,8 @@ export function run(app) {
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
res.send(`whoooops<br>${err}`);
|
res.send(`whoooops<br>${err}`);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
logger.error(err);
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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>`);
|
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>`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue