Clean up apis
This commit is contained in:
parent
7371cc8851
commit
d7d3c63d7f
0
.env.example
Executable file → Normal file
0
.env.example
Executable file → Normal file
0
.eslintrc.cjs
Executable file → Normal file
0
.eslintrc.cjs
Executable file → Normal file
0
.gitignore
vendored
Executable file → Normal file
0
.gitignore
vendored
Executable file → Normal file
0
drizzle.config.ts
Executable file → Normal file
0
drizzle.config.ts
Executable file → Normal file
0
next.config.js
Executable file → Normal file
0
next.config.js
Executable file → Normal file
0
package.json
Executable file → Normal file
0
package.json
Executable file → Normal file
0
pnpm-lock.yaml
generated
Executable file → Normal file
0
pnpm-lock.yaml
generated
Executable file → Normal file
0
postcss.config.cjs
Executable file → Normal file
0
postcss.config.cjs
Executable file → Normal file
0
prettier.config.js
Executable file → Normal file
0
prettier.config.js
Executable file → Normal file
0
public/favicon.png
Executable file → Normal file
0
public/favicon.png
Executable file → Normal file
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
@ -4,15 +4,18 @@ import type { NextRequest } from "next/server";
|
||||
import { createOrUpdateCountdown } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const middlewareResponse = middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { relationshipId, title, date } = await request.json() as {
|
||||
type CreateOrUpdateCountdownRequest = {
|
||||
relationshipId: string;
|
||||
title: string;
|
||||
date: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { relationshipId, title, date } =
|
||||
await request.json()as CreateOrUpdateCountdownRequest;
|
||||
await createOrUpdateCountdown(Number.parseInt(relationshipId), title, new Date(date));
|
||||
return NextResponse.json({ message: "Countdown created or updated successfully" });
|
||||
} catch (error) {
|
||||
|
@ -1,21 +1,19 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { getCountdownByRelationship } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
export const GET = async (request: Request) => {
|
||||
export const GET = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const apiKey = url.searchParams.get("apiKey");
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
} else {
|
||||
const relationshipId = url.searchParams.get("relationshipId");
|
||||
if (!relationshipId)
|
||||
const { searchParams } = new URL(request.url);
|
||||
const relationshipId: string | null = searchParams.get("relationshipId");
|
||||
if (!relationshipId || isNaN(parseInt(relationshipId)))
|
||||
return NextResponse.json({ message: "Invalid relationshipId" }, { status: 400 });
|
||||
const countdown = await getCountdownByRelationship(parseInt(relationshipId));
|
||||
return NextResponse.json(countdown);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ message: "Error" }, { status: 500 });
|
||||
|
@ -1,24 +1,20 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { fetchMessages } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
export const GET = async (request: Request) => {
|
||||
export const GET = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const apiKey = url.searchParams.get("apiKey");
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
} else {
|
||||
const userId = url.searchParams.get("userId");
|
||||
if (!userId)
|
||||
return NextResponse.json({ message: "Invalid userId" }, { status: 400 });
|
||||
const partnerId = url.searchParams.get("partnerId");
|
||||
if (!partnerId)
|
||||
return NextResponse.json({ message: "Invalid partnerId" }, { status: 400 });
|
||||
const { searchParams } = new URL(request.url);
|
||||
const userId: string | null = searchParams.get("userId");
|
||||
const partnerId: string | null = searchParams.get("partnerId");
|
||||
if (!userId || !partnerId || isNaN(parseInt(userId)) || isNaN(parseInt(partnerId)))
|
||||
return NextResponse.json({ message: "Invalid userId or partnerId" }, { status: 400 });
|
||||
const messages = await fetchMessages(parseInt(userId), parseInt(partnerId));
|
||||
return NextResponse.json(messages);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ message: "Error" }, { status: 500 });
|
||||
|
@ -2,6 +2,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { sendMessage } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
type sendMessageRequest = {
|
||||
senderId: number;
|
||||
@ -12,24 +13,18 @@ type sendMessageRequest = {
|
||||
};
|
||||
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const apiKey = url.searchParams.get("apiKey");
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
const body = await request.json() as sendMessageRequest;
|
||||
const {
|
||||
senderId,
|
||||
receiverId,
|
||||
content,
|
||||
mediaUrl = "",
|
||||
mediaType = "text",
|
||||
} = body;
|
||||
if (!senderId || !receiverId || !content) {
|
||||
} = await request.json() as sendMessageRequest;
|
||||
if (!senderId || !receiverId || !content || isNaN(senderId) || isNaN(receiverId))
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
}
|
||||
const message = await sendMessage(senderId, receiverId, content, mediaUrl, mediaType);
|
||||
return NextResponse.json(message, { status: 201 });
|
||||
} catch (error) {
|
||||
|
@ -1,26 +1,23 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { createRelationshipRequest } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
type CreateRequestRequest = {
|
||||
apiKey: string;
|
||||
userId: number;
|
||||
targetUserId: number;
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, userId, targetUserId } = await request.json() as CreateRequestRequest;
|
||||
console.log("Received request:", { apiKey, userId, targetUserId });
|
||||
const { userId, targetUserId } = await request.json() as CreateRequestRequest;
|
||||
console.log("Received request:", { userId, targetUserId });
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!userId || !targetUserId) {
|
||||
if (!userId || !targetUserId || isNaN(userId) || isNaN(targetUserId))
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
}
|
||||
|
||||
console.log("Creating relationship request for user:", userId);
|
||||
const result = await createRelationshipRequest(userId, targetUserId);
|
||||
|
@ -1,28 +1,20 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { deleteRelationship } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
interface DeleteRelationshipRequest {
|
||||
apiKey: string;
|
||||
relationshipId: number;
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, relationshipId } = await request.json() as DeleteRelationshipRequest;
|
||||
console.log("Received request:", { apiKey, relationshipId });
|
||||
const { relationshipId } = await request.json() as { relationshipId: string };
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!relationshipId) {
|
||||
if (!relationshipId || isNaN(parseInt(relationshipId)))
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
}
|
||||
|
||||
console.log("Deleting relationship:", relationshipId);
|
||||
const result = await deleteRelationship(relationshipId);
|
||||
const result = await deleteRelationship(parseInt(relationshipId));
|
||||
|
||||
if (result.success) {
|
||||
console.log("Relationship deleted successfully");
|
||||
|
@ -1,26 +1,23 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { updateRelationshipRequest } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
interface UpdateRequestRequest {
|
||||
apiKey: string;
|
||||
relationshipId: number;
|
||||
status: 'accepted' | 'rejected';
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, relationshipId, status } = await request.json() as UpdateRequestRequest;
|
||||
console.log("Received request:", { apiKey, relationshipId, status });
|
||||
const { relationshipId, status } = await request.json() as UpdateRequestRequest;
|
||||
console.log("Received request:", { relationshipId, status });
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!relationshipId || !status) {
|
||||
if (!relationshipId || !status || isNaN(relationshipId))
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
}
|
||||
|
||||
console.log("Updating relationship request:", relationshipId);
|
||||
const result = await updateRelationshipRequest(relationshipId, status);
|
||||
|
@ -1,21 +1,19 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
import { updateUserPushToken } from '~/server/functions';
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
type Data = {
|
||||
apiKey: string;
|
||||
userId: string;
|
||||
pushToken: string;
|
||||
};
|
||||
|
||||
export const POST = async (request: Request) => {
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, userId, pushToken } = await request.json() as Data;
|
||||
console.log('Received request:', { apiKey, userId, pushToken });
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log('Invalid API Key');
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
const { userId, pushToken } = await request.json() as Data;
|
||||
console.log('Received request:', { userId, pushToken });
|
||||
|
||||
console.log('Updating push token for user:', userId);
|
||||
await updateUserPushToken(parseInt(userId), pushToken);
|
||||
|
@ -1,23 +1,21 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { changePassword } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
type Data = {
|
||||
apiKey: string;
|
||||
userId: number;
|
||||
oldPassword: string;
|
||||
newPassword: string;
|
||||
};
|
||||
|
||||
export const POST = async (request: Request) => {
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, userId, oldPassword, newPassword } = await request.json() as Data;
|
||||
console.log("Received request:", { apiKey, userId, oldPassword, newPassword });
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
const { userId, oldPassword, newPassword } = await request.json() as Data;
|
||||
console.log("Received request:", { userId, oldPassword, newPassword });
|
||||
|
||||
console.log("Changing password for user:", userId);
|
||||
await changePassword(userId, oldPassword, newPassword);
|
||||
|
@ -1,6 +1,8 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { createUser } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
type CreateUserRequest = {
|
||||
username: string;
|
||||
@ -11,20 +13,10 @@ type CreateUserRequest = {
|
||||
pushToken?: string;
|
||||
};
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const apiKey = url.searchParams.get("apiKey");
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
|
||||
// Parse the request body instead of using URL parameters for POST requests
|
||||
const body = await request.json() as CreateUserRequest;
|
||||
|
||||
// Destructure the body with default values for optional fields
|
||||
const {
|
||||
username,
|
||||
email,
|
||||
@ -32,7 +24,7 @@ export async function POST(request: Request) {
|
||||
name,
|
||||
pfpURL = "",
|
||||
pushToken = ""
|
||||
} = body;
|
||||
} = await request.json() as CreateUserRequest;
|
||||
|
||||
// Validate required fields
|
||||
if (!username || !email || !passwordHash || !name) {
|
||||
|
@ -1,22 +1,19 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { getUserById } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
export const GET = async (request: Request) => {
|
||||
export const GET = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const apiKey = url.searchParams.get("apiKey");
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
} else {
|
||||
const userId = url.searchParams.get("userId");
|
||||
if (!userId) {
|
||||
if (!userId || isNaN(parseInt(userId)))
|
||||
return NextResponse.json({ message: "Invalid userId" }, { status: 400 });
|
||||
}
|
||||
const user = await getUserById(parseInt(userId));
|
||||
return NextResponse.json(user);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ message: "Error" }, { status: 500 });
|
||||
|
@ -1,19 +1,17 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { getUserByUsername } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
export const GET = async (request: Request) => {
|
||||
export const GET = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const apiKey = url.searchParams.get("apiKey");
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
} else {
|
||||
const username = url.searchParams.get("username") ?? "2";
|
||||
const user = await getUserByUsername(username);
|
||||
return NextResponse.json(user);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ message: "Error" }, { status: 500 });
|
||||
|
@ -1,22 +1,20 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { login } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
interface LoginRequest {
|
||||
apiKey: string;
|
||||
type LoginRequest = {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, username, password } = await request.json() as LoginRequest;
|
||||
console.log("Received request:", { apiKey, username, password });
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
const { username, password } = await request.json() as LoginRequest;
|
||||
console.log("Received request:", { username, password });
|
||||
|
||||
if (!username || !password) {
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
|
@ -6,7 +6,7 @@ import { middleware } from "~/middleware";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const middlewareResponse = middleware(request);
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
|
||||
try {
|
||||
|
@ -5,7 +5,7 @@ import { refreshToken } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = middleware(request);
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { refreshToken: token } = await request.json() as { refreshToken: string };
|
||||
|
@ -1,26 +1,23 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { updateUserPFP } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
interface UpdatePfpRequest {
|
||||
apiKey: string;
|
||||
userId: number;
|
||||
pfpURL: string;
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, userId, pfpURL } = await request.json() as UpdatePfpRequest;
|
||||
console.log("Received request:", { apiKey, userId, pfpURL });
|
||||
const { userId, pfpURL } = await request.json() as UpdatePfpRequest;
|
||||
console.log("Received request:", { userId, pfpURL });
|
||||
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!userId || !pfpURL) {
|
||||
if (!userId || !pfpURL || isNaN(userId))
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
}
|
||||
|
||||
console.log("Updating profile picture for user:", userId);
|
||||
const result = await updateUserPFP(userId, pfpURL);
|
||||
|
@ -1,25 +1,27 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { updateUserPushToken } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
interface UpdatePushTokenRequest {
|
||||
apiKey: string;
|
||||
userId: number;
|
||||
pushToken: string;
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { apiKey, userId, pushToken } = await request.json() as UpdatePushTokenRequest;
|
||||
console.log("Received request:", { apiKey, userId, pushToken });
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
console.log("Invalid API Key");
|
||||
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
|
||||
}
|
||||
if (!userId || !pushToken)
|
||||
const { userId, pushToken } = await request.json() as UpdatePushTokenRequest;
|
||||
console.log("Received request:", { userId, pushToken });
|
||||
|
||||
if (!userId || !pushToken || isNaN(userId))
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
|
||||
console.log("Updating push token for user:", userId);
|
||||
const result = await updateUserPushToken(userId, pushToken);
|
||||
|
||||
if (result.success) {
|
||||
console.log("Push token updated successfully");
|
||||
return NextResponse.json({ message: "Push token updated successfully" });
|
||||
|
0
src/app/layout.tsx
Executable file → Normal file
0
src/app/layout.tsx
Executable file → Normal file
0
src/app/page.tsx
Executable file → Normal file
0
src/app/page.tsx
Executable file → Normal file
0
src/env.js
Executable file → Normal file
0
src/env.js
Executable file → Normal file
@ -1,11 +1,20 @@
|
||||
import type { NextRequest } from 'next/server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
export async function middleware(request: NextRequest): Promise<NextResponse | undefined> {
|
||||
try {
|
||||
const apiKey = request.headers.get('x-api-key');
|
||||
|
||||
if (!apiKey || apiKey !== process.env.API_KEY)
|
||||
if (!apiKey || apiKey !== process.env.API_KEY) {
|
||||
return NextResponse.json({ message: 'Invalid API key' }, { status: 401 });
|
||||
}
|
||||
|
||||
// If the API key is valid, we don't return anything, allowing the request to proceed
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
console.error('Middleware error:', error);
|
||||
return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export const config = {
|
||||
|
0
src/server/db/index.ts
Executable file → Normal file
0
src/server/db/index.ts
Executable file → Normal file
0
src/server/db/schema.ts
Executable file → Normal file
0
src/server/db/schema.ts
Executable file → Normal file
0
src/server/functions.ts
Executable file → Normal file
0
src/server/functions.ts
Executable file → Normal file
0
src/styles/globals.css
Executable file → Normal file
0
src/styles/globals.css
Executable file → Normal file
0
tailwind.config.ts
Executable file → Normal file
0
tailwind.config.ts
Executable file → Normal file
0
tsconfig.json
Executable file → Normal file
0
tsconfig.json
Executable file → Normal file
Loading…
Reference in New Issue
Block a user