feat: add scoped app name

This commit is contained in:
crazywoola
2023-06-21 17:12:52 +08:00
parent 940f2e7507
commit 4b21c0cc82
2 changed files with 6 additions and 2 deletions
+3 -1
View File
@@ -1,2 +1,4 @@
# you can find this in https://cloud.dify.ai/
API_SECRET=YOUR_API_SECRET
APP_ID=YOUR_APP_ID # This is your APP ID aka APP NAME will be used for generate user id under this scope
API_SECRET=YOUR_API_SECRET # This is your API Secret
+3 -1
View File
@@ -1,6 +1,8 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { v4 } from 'uuid'
import dotenv from 'dotenv'
dotenv.config()
export function middleware(request: NextRequest) {
const response = NextResponse.next()
@@ -10,7 +12,7 @@ export function middleware(request: NextRequest) {
}
// Check and set the user cookie if it doesn't exist
if (!request.cookies.has('user')) {
response.cookies.set('user', v4())
response.cookies.set('user', `${process.env.APP_ID}_${v4()}`)
}
return response
}