panhong d63bf0bda5
添加 react 编写的新版 WEBUI (#3417)
* feat:提交前端代码

* feat:提交logo样式切换

* feat:替换avatar、部分位置icon、chatchat相关说明、git链接、Wiki链接、关于、设置、反馈与建议等功能,关闭lobehub自检更新功能

* fix:移除多余代码

---------

Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
2024-03-19 14:30:26 +08:00

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;