From a8ea35e5c60852231076b9cb170817d63aa788d7 Mon Sep 17 00:00:00 2001 From: p-sunshijun Date: Wed, 11 Dec 2024 18:08:47 +0800 Subject: [PATCH] fix: add new setting item to disable/enable same site property fixes #55 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙世军 <1083433931@qq.com> --- .idea/workspace.xml | 65 +++++++++++++++++++++++++++++++++++++++++ app/api/utils/common.ts | 7 +++-- config/index.ts | 1 + types/app.ts | 1 + 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..ae1f338d --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + \ No newline at end of file diff --git a/app/api/utils/common.ts b/app/api/utils/common.ts index 109ee4b0..27c1126d 100644 --- a/app/api/utils/common.ts +++ b/app/api/utils/common.ts @@ -1,7 +1,7 @@ import { type NextRequest } from 'next/server' import { ChatClient } from 'dify-client' import { v4 } from 'uuid' -import { API_KEY, API_URL, APP_ID } from '@/config' +import { API_KEY, API_URL, APP_ID, APP_INFO } from '@/config' const userPrefix = `user_${APP_ID}:` @@ -15,7 +15,10 @@ export const getInfo = (request: NextRequest) => { } export const setSession = (sessionId: string) => { - return { 'Set-Cookie': `session_id=${sessionId}` } + if (APP_INFO.disable_session_same_site) + return { 'Set-Cookie': `session_id=${sessionId}; SameSite=None; Secure` } + + return { 'Set-Cookie': `session_id=${sessionId}` } } export const client = new ChatClient(API_KEY, API_URL || undefined) diff --git a/config/index.ts b/config/index.ts index eb726f1a..74c97586 100644 --- a/config/index.ts +++ b/config/index.ts @@ -8,6 +8,7 @@ export const APP_INFO: AppInfo = { copyright: '', privacy_policy: '', default_language: 'en', + disable_session_same_site: false, // set it to true if you want to embed the chatbot in an iframe } export const isShowPrompt = false diff --git a/types/app.ts b/types/app.ts index 3d62c4fb..197f6be6 100644 --- a/types/app.ts +++ b/types/app.ts @@ -108,6 +108,7 @@ export type AppInfo = { default_language: Locale copyright?: string privacy_policy?: string + disable_session_same_site?: boolean } export enum Resolution {