mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-30 02:35:29 +08:00
* feat:提交前端代码 * feat:提交logo样式切换 * feat:替换avatar、部分位置icon、chatchat相关说明、git链接、Wiki链接、关于、设置、反馈与建议等功能,关闭lobehub自检更新功能 * fix:移除多余代码 --------- Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
35 lines
966 B
TypeScript
35 lines
966 B
TypeScript
import { NextResponse } from 'next/server';
|
|
|
|
import { getServerConfig } from '@/config/server';
|
|
|
|
import { auth } from './app/api/auth/next-auth';
|
|
import { OAUTH_AUTHORIZED } from './const/auth';
|
|
|
|
export const config = {
|
|
matcher: '/api/:path*',
|
|
};
|
|
const defaultMiddleware = () => NextResponse.next();
|
|
|
|
const withAuthMiddleware = auth((req) => {
|
|
// Just check if session exists
|
|
const session = req.auth;
|
|
|
|
// Check if next-auth throws errors
|
|
// refs: https://github.com/lobehub/lobe-chat/pull/1323
|
|
const isLoggedIn = !!session?.expires;
|
|
|
|
// Remove & amend OAuth authorized header
|
|
const requestHeaders = new Headers(req.headers);
|
|
requestHeaders.delete(OAUTH_AUTHORIZED);
|
|
if (isLoggedIn) requestHeaders.set(OAUTH_AUTHORIZED, 'true');
|
|
return NextResponse.next({
|
|
request: {
|
|
headers: requestHeaders,
|
|
},
|
|
});
|
|
});
|
|
|
|
const { ENABLE_OAUTH_SSO } = getServerConfig();
|
|
|
|
export default !ENABLE_OAUTH_SSO ? defaultMiddleware : withAuthMiddleware;
|