Skip to content

Commit 42ca588

Browse files
committed
feat: added api key auth
1 parent f5dc5b2 commit 42ca588

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/app/(ui)/(public)/login/components/login-form.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function LoginForm({ className, ...props }: LoginFormProps) {
6464
</FormItem>
6565
)}
6666
/>
67-
<Button className='mt-2 cursor-pointer' disabled={loginMutation.isPending}>
67+
<Button className='mt-8 cursor-pointer' disabled={loginMutation.isPending}>
6868
Login
6969
</Button>
7070
</div>

src/middleware.ts

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ export async function middleware(req: NextRequest) {
1010
return NextResponse.next();
1111
}
1212
const authHeader = req.headers.get("Authorization");
13+
const apiKey = req.headers.get("x-api-key");
14+
15+
if (apiKey) {
16+
const validApiKey = await prisma.apiKeys.findUnique({
17+
where: { key: apiKey },
18+
});
19+
20+
if (validApiKey) {
21+
const res = NextResponse.next();
22+
res.headers.set("x-auth-method", "api-key");
23+
return res;
24+
}
25+
}
26+
1327
if (!authHeader) {
1428
return NextResponse.json(
1529
{

0 commit comments

Comments
 (0)