From 06b9678fe11b80678db6239c8f423002fdd5e000 Mon Sep 17 00:00:00 2001 From: chenpei Date: Mon, 6 Jul 2026 14:39:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E9=92=89=E9=92=89=E7=9B=B4?= =?UTF-8?q?=E8=BE=BE=E7=99=BB=E5=BD=95Cookie=E8=90=BD=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/dingtalk/callback/route.ts | 47 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/app/api/dingtalk/callback/route.ts b/app/api/dingtalk/callback/route.ts index 3b2904e8..94daf667 100644 --- a/app/api/dingtalk/callback/route.ts +++ b/app/api/dingtalk/callback/route.ts @@ -1,5 +1,5 @@ import { NextResponse, type NextRequest } from 'next/server' -import { parseDingtalkOAuthState } from '@/lib/dingtalk-oauth' +import { DINGTALK_DIRECT_LOGIN_SOURCE, parseDingtalkOAuthState } from '@/lib/dingtalk-oauth' import { getPublicAppOrigin } from '@/lib/public-app-url' import { buildDingtalkAutoLoginPath } from '@/lib/safe-redirect' @@ -32,9 +32,48 @@ function getInternalLoginUrl() { return `http://127.0.0.1:${port}/api/dingtalk/login` } +function createCookieLandingResponse(redirectPath: string, loginResponse: Response) { + const escapedPath = JSON.stringify(redirectPath).replace(/ + + + + + 正在进入素材库 + + + + +
+

登录成功

+

正在进入考核调研...

+
+ + +`, + { + status: 200, + headers: { + 'Content-Type': 'text/html; charset=utf-8', + 'Cache-Control': 'no-store, no-cache, must-revalidate, max-age=0', + }, + }, + ) + + appendLoginSetCookie(response, loginResponse) + return response +} + export async function GET(request: NextRequest) { const code = request.nextUrl.searchParams.get('code') || request.nextUrl.searchParams.get('authCode') - const { redirectPath } = parseDingtalkOAuthState(request.nextUrl.searchParams.get('state')) + const { redirectPath, source } = parseDingtalkOAuthState(request.nextUrl.searchParams.get('state')) const publicOrigin = getPublicAppOrigin() if (!code) { @@ -62,6 +101,10 @@ export async function GET(request: NextRequest) { return NextResponse.redirect(url) } + if (source === DINGTALK_DIRECT_LOGIN_SOURCE) { + return createCookieLandingResponse(redirectPath, loginResponse) + } + const redirectResponse = NextResponse.redirect(new URL(redirectPath, publicOrigin)) appendLoginSetCookie(redirectResponse, loginResponse) redirectResponse.headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')