Protocol modif

This commit is contained in:
ExostFlash 2025-08-28 14:09:18 +02:00
parent 7647bcd52a
commit 830b60dad0
3 changed files with 9 additions and 3 deletions

2
app.js
View file

@ -93,7 +93,7 @@ async function start() {
try { try {
await app.ready(); await app.ready();
app.swagger(); app.swagger();
await app.listen({ port: 3000, host: 'localhost' }); await app.listen({ port: 3000, host: '0.0.0.0' });
app.log.info('Server listening on http://localhost:3000'); app.log.info('Server listening on http://localhost:3000');
} catch (err) { } catch (err) {
app.log.error(err); app.log.error(err);

View file

@ -3,9 +3,12 @@ const db = require('./db');
const BOT_ID = "1410578978712060024"; const BOT_ID = "1410578978712060024";
const BOT_SECRET = "vhk6jp_jYjvShOqpI8MJ2Efjjm_9Cmyi"; const BOT_SECRET = "vhk6jp_jYjvShOqpI8MJ2Efjjm_9Cmyi";
const REDIRECT_URI = "http://localhost:3000/auth/discord/callback";
exports.handleDiscordAuth = async (request, reply) => { exports.handleDiscordAuth = async (request, reply) => {
const protocol = request.protocol || (request.headers['x-forwarded-proto'] || '').split(',')[0] || 'http';
const host = request.hostname || request.headers.host;
const REDIRECT_URI = `${protocol}://${host}/auth/discord/callback`;
const code = request.query.code; const code = request.query.code;
if (!code) return reply.code(400).send({ error: "Code de validation manquant" }); if (!code) return reply.code(400).send({ error: "Code de validation manquant" });
try { try {

View file

@ -10,8 +10,11 @@ module.exports = async function (app, opts) {
// --- Auth Discord --- // --- Auth Discord ---
app.get('/auth/discord', async (req, reply) => { app.get('/auth/discord', async (req, reply) => {
const protocol = req.protocol || (req.headers['x-forwarded-proto'] || '').split(',')[0] || 'http';
const host = req.hostname || req.headers.host;
const redirectUri = `${protocol}://${host}/auth/discord/callback`;
const clientId = '1410578978712060024'; const clientId = '1410578978712060024';
const redirectUri = 'http://localhost:3000/auth/discord/callback';
const scope = 'identify email'; const scope = 'identify email';
const discordAuthUrl = `https://discord.com/api/oauth2/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${scope}`; const discordAuthUrl = `https://discord.com/api/oauth2/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${scope}`;
reply.redirect(discordAuthUrl); reply.redirect(discordAuthUrl);