feat: 首页支持宣传语
This commit is contained in:
24
lib/auth/request.ts
Normal file
24
lib/auth/request.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { validateApiKey } from "@/lib/auth/api-key";
|
||||
|
||||
/**
|
||||
* Authenticate an API request with Bearer token
|
||||
* Returns the claw object if authenticated, or a 401 NextResponse if not
|
||||
*/
|
||||
export async function authenticateRequest(req: NextRequest) {
|
||||
const authHeader = req.headers.get("authorization");
|
||||
if (!authHeader?.startsWith("Bearer ")) {
|
||||
return NextResponse.json(
|
||||
{ error: "Missing or invalid authorization header" },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
const apiKey = authHeader.slice(7);
|
||||
const claw = await validateApiKey(apiKey);
|
||||
if (!claw) {
|
||||
return NextResponse.json({ error: "Invalid API key" }, { status: 401 });
|
||||
}
|
||||
|
||||
return { claw };
|
||||
}
|
||||
24
lib/utils.ts
24
lib/utils.ts
@@ -1,7 +1,5 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { validateApiKey } from "@/lib/auth/api-key";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
@@ -13,25 +11,3 @@ export function cn(...inputs: ClassValue[]) {
|
||||
export function getTodayDateString(): string {
|
||||
return new Date().toISOString().split("T")[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate an API request with Bearer token
|
||||
* Returns the claw object if authenticated, or a 401 NextResponse if not
|
||||
*/
|
||||
export async function authenticateRequest(req: NextRequest) {
|
||||
const authHeader = req.headers.get("authorization");
|
||||
if (!authHeader?.startsWith("Bearer ")) {
|
||||
return NextResponse.json(
|
||||
{ error: "Missing or invalid authorization header" },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
const apiKey = authHeader.slice(7);
|
||||
const claw = await validateApiKey(apiKey);
|
||||
if (!claw) {
|
||||
return NextResponse.json({ error: "Invalid API key" }, { status: 401 });
|
||||
}
|
||||
|
||||
return { claw };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user