diff --git a/code/websites/pokedex.online/server/oauth-proxy.js b/code/websites/pokedex.online/server/oauth-proxy.js index 21fd1ac..65922dd 100644 --- a/code/websites/pokedex.online/server/oauth-proxy.js +++ b/code/websites/pokedex.online/server/oauth-proxy.js @@ -42,7 +42,8 @@ app.use('/api/gamemaster', gamemasterRouter); * POST /oauth/token */ app.post('/oauth/token', async (req, res) => { - if (!hasChallongeAuth) { + if (!config.challonge.configured) { + logger.warn('OAuth token request received but Challonge not configured'); return res.status(503).json({ error: 'Challonge OAuth not configured', message: @@ -53,10 +54,12 @@ app.post('/oauth/token', async (req, res) => { const { code } = req.body; if (!code) { + logger.warn('OAuth token request missing authorization code'); return res.status(400).json({ error: 'Missing authorization code' }); } try { + logger.debug('Exchanging authorization code for access token'); const response = await fetch('https://api.challonge.com/oauth/token', { method: 'POST', headers: { @@ -64,24 +67,24 @@ app.post('/oauth/token', async (req, res) => { }, body: new URLSearchParams({ grant_type: 'authorization_code', - client_id: CLIENT_ID, - client_secret: CLIENT_SECRET, + client_id: config.challonge.clientId, + client_secret: config.challonge.clientSecret, code: code, - redirect_uri: REDIRECT_URI + redirect_uri: config.challonge.redirectUri }) }); const data = await response.json(); if (!response.ok) { - console.error('Token exchange failed:', data); + logger.error('Token exchange failed', { status: response.status, data }); return res.status(response.status).json(data); } - console.log('✅ Token exchange successful'); + logger.info('Token exchange successful'); res.json(data); } catch (error) { - console.error('Token exchange error:', error); + logger.error('Token exchange error', { error: error.message }); res.status(500).json({ error: 'Token exchange failed', message: error.message