mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 15:46:39 +08:00
用户信息api添加管理员授权
This commit is contained in:
parent
45fa760db1
commit
72d1330fc2
@ -46,7 +46,7 @@ function UserTableSearchInput({ users, setUsers, setLoading }: UserInterface) {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const fetchUsers = async () => {
|
const fetchUsers = async () => {
|
||||||
try {
|
try {
|
||||||
const url = new URL("/api/admin/users/", "http://localhost:3000");
|
const url = new URL("/api/admin/users/", window.location.href);
|
||||||
url.searchParams.append("search", searchText);
|
url.searchParams.append("search", searchText);
|
||||||
console.log(url, "url");
|
console.log(url, "url");
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import type { NextRequest } from "next/server";
|
import type { NextRequest } from "next/server";
|
||||||
import { getToken } from "next-auth/jwt";
|
import { getToken } from "next-auth/jwt";
|
||||||
import { DENY_LIST, isName } from "@/lib/auth_list";
|
import { DENY_LIST, isName, ADMIN_LIST } from "@/lib/auth_list";
|
||||||
|
|
||||||
export default async function middleware(req: NextRequest) {
|
export default async function middleware(req: NextRequest) {
|
||||||
const url = req.nextUrl;
|
const url = req.nextUrl;
|
||||||
@ -16,6 +16,18 @@ export default async function middleware(req: NextRequest) {
|
|||||||
|
|
||||||
const session = await getToken({ req });
|
const session = await getToken({ req });
|
||||||
|
|
||||||
|
// 管理员页面的api接口还是要认证的
|
||||||
|
if (path.startsWith('/api/admin/')) {
|
||||||
|
let is_admin_user = false;
|
||||||
|
// 需要确认是管理员
|
||||||
|
if (session && session?.user) {
|
||||||
|
if (ADMIN_LIST.includes(session?.name ?? "")) {
|
||||||
|
is_admin_user = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_admin_user) return NextResponse.json({error: '无管理员授权'}, { status: 401 });
|
||||||
|
|
||||||
|
}
|
||||||
// console.log('==============,认证,', path, session)
|
// console.log('==============,认证,', path, session)
|
||||||
// 认证有点多此一举,页面中的认证应该已经够了
|
// 认证有点多此一举,页面中的认证应该已经够了
|
||||||
// if (!session && path !== "/login") {
|
// if (!session && path !== "/login") {
|
||||||
|
Loading…
Reference in New Issue
Block a user