feat(web): add desktop callback API route
Server-side redirect to deep link for production builds. More reliable than client-side window.location.href. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
57cb99dbba
commit
f0c9c43678
1 changed files with 38 additions and 0 deletions
38
apps/web/app/api/desktop/callback/route.ts
Normal file
38
apps/web/app/api/desktop/callback/route.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
/**
|
||||
* Desktop Callback API
|
||||
*
|
||||
* Server-side redirect to deep link (multica://auth?...)
|
||||
* This is more reliable than client-side window.location.href
|
||||
*
|
||||
* Reference: Cap/apps/web/app/api/desktop/[...route]/session.ts
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = request.nextUrl;
|
||||
const sid = searchParams.get('sid');
|
||||
const user = searchParams.get('user');
|
||||
const port = searchParams.get('port');
|
||||
const platform = searchParams.get('platform') || 'desktop';
|
||||
|
||||
// Validate required params
|
||||
if (!sid || !user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Missing sid or user parameter' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Build callback URL
|
||||
const params = new URLSearchParams({ sid, user });
|
||||
|
||||
if (platform === 'web' && port) {
|
||||
// Dev mode: redirect to local server
|
||||
const callbackUrl = `http://127.0.0.1:${port}/callback?${params}`;
|
||||
return NextResponse.redirect(callbackUrl);
|
||||
} else {
|
||||
// Production mode: redirect to deep link
|
||||
const deepLinkUrl = `multica://auth?${params}`;
|
||||
return NextResponse.redirect(deepLinkUrl);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue