Spaces:
Sleeping
Sleeping
Sasha commited on
Commit ·
2b682ac
1
Parent(s): 7c10755
fix: production oauth redirect to frontend host
Browse files- server/server.js +17 -6
server/server.js
CHANGED
|
@@ -434,9 +434,25 @@ app.get('/api/auth/twitch', (req, res) => {
|
|
| 434 |
app.get('/api/auth/twitch/callback', async (req, res) => {
|
| 435 |
const { code, error } = req.query;
|
| 436 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
if (error) {
|
| 438 |
console.error('Twitch OAuth error callback:', error);
|
| 439 |
-
return res.redirect(
|
| 440 |
}
|
| 441 |
|
| 442 |
try {
|
|
@@ -528,11 +544,6 @@ app.get('/api/auth/twitch/callback', async (req, res) => {
|
|
| 528 |
};
|
| 529 |
|
| 530 |
console.log(`[Auth] User ${displayName} logged in. Role: ${role}`);
|
| 531 |
-
|
| 532 |
-
// Redirect to frontend (in local dev it could redirect to port 5173, in prod to root)
|
| 533 |
-
const frontendRedirect = process.env.NODE_ENV === 'production'
|
| 534 |
-
? '/'
|
| 535 |
-
: 'http://localhost:5173/';
|
| 536 |
|
| 537 |
res.redirect(frontendRedirect);
|
| 538 |
} catch (err) {
|
|
|
|
| 434 |
app.get('/api/auth/twitch/callback', async (req, res) => {
|
| 435 |
const { code, error } = req.query;
|
| 436 |
|
| 437 |
+
let frontendRedirect = '/';
|
| 438 |
+
if (process.env.NODE_ENV === 'production') {
|
| 439 |
+
if (process.env.TWITCH_REDIRECT_URI) {
|
| 440 |
+
try {
|
| 441 |
+
const redirectUrl = new URL(process.env.TWITCH_REDIRECT_URI);
|
| 442 |
+
frontendRedirect = `${redirectUrl.protocol}//${redirectUrl.host}/`;
|
| 443 |
+
} catch (e) {
|
| 444 |
+
frontendRedirect = 'https://mimic42.qzz.io/';
|
| 445 |
+
}
|
| 446 |
+
} else {
|
| 447 |
+
frontendRedirect = 'https://mimic42.qzz.io/';
|
| 448 |
+
}
|
| 449 |
+
} else {
|
| 450 |
+
frontendRedirect = 'http://localhost:5173/';
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
if (error) {
|
| 454 |
console.error('Twitch OAuth error callback:', error);
|
| 455 |
+
return res.redirect(`${frontendRedirect}auth-failed`);
|
| 456 |
}
|
| 457 |
|
| 458 |
try {
|
|
|
|
| 544 |
};
|
| 545 |
|
| 546 |
console.log(`[Auth] User ${displayName} logged in. Role: ${role}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
|
| 548 |
res.redirect(frontendRedirect);
|
| 549 |
} catch (err) {
|