Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pages/api/auth/roblox/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function handler(req: AuthenticatedRequest, res: NextApiRes
let clientId: string | undefined;
let redirectUri: string | undefined;
clientId = process.env.ROBLOX_CLIENT_ID;
redirectUri = `${process.env.PLANETARY_CLOUD_URL ? `https://${process.env.PLANETARY_CLOUD_URL}` : process.env.NEXTAUTH_URL || process.env.PUBLIC_URL}/api/auth/discord/callback`;
redirectUri = `${process.env.PLANETARY_CLOUD_URL ? `https://${process.env.PLANETARY_CLOUD_URL}` : process.env.NEXTAUTH_URL || process.env.PUBLIC_URL}/api/auth/roblox/callback`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reuse the callback’s redirect URI resolution.

pages/api/auth/roblox/callback.ts honors ROBLOX_REDIRECT_URI and instanceConfig.robloxRedirectUri, but this line always derives the URI from base URL variables. When an override is configured, Roblox receives one redirect_uri during authorization and a different one during token exchange, causing the OAuth flow to fail. Use a shared resolver or identical precedence here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pages/api/auth/roblox/start.ts` at line 18, Update the redirect URI
assignment in the Roblox start handler to use the same resolver and precedence
as the callback handler, including ROBLOX_REDIRECT_URI and
instanceConfig.robloxRedirectUri overrides before base URL fallbacks. Ensure
authorization and token exchange send the identical callback URI, preferably by
reusing the callback’s shared resolver.

if (!clientId || !redirectUri) {
try {
const configs = await prisma.instanceConfig.findMany({
Expand Down Expand Up @@ -55,4 +55,4 @@ export default async function handler(req: AuthenticatedRequest, res: NextApiRes
authUrl.searchParams.set('state', state);

res.redirect(authUrl.toString());
}
}