build fix
This commit is contained in:
14
lib/auth.ts
14
lib/auth.ts
@@ -1,3 +1,4 @@
|
|||||||
|
import type Database from "better-sqlite3";
|
||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
@@ -62,12 +63,7 @@ function decodeSession(value: string | undefined): SessionPayload | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bootstrapAdminUser(db: {
|
export function bootstrapAdminUser(db: Database.Database) {
|
||||||
prepare: (sql: string) => {
|
|
||||||
get: (...args: unknown[]) => unknown;
|
|
||||||
run: (...args: unknown[]) => unknown;
|
|
||||||
};
|
|
||||||
}) {
|
|
||||||
const countRow = db.prepare(`SELECT COUNT(*) AS count FROM users`).get() as { count: number };
|
const countRow = db.prepare(`SELECT COUNT(*) AS count FROM users`).get() as { count: number };
|
||||||
|
|
||||||
if ((countRow.count ?? 0) > 0) {
|
if ((countRow.count ?? 0) > 0) {
|
||||||
@@ -121,11 +117,7 @@ export async function destroySession() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function authenticateUser(
|
export function authenticateUser(
|
||||||
db: {
|
db: Database.Database,
|
||||||
prepare: (sql: string) => {
|
|
||||||
get: (...args: unknown[]) => unknown;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
email: string,
|
email: string,
|
||||||
password: string
|
password: string
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ async function hasValidSession(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function middleware(request: NextRequest) {
|
export async function proxy(request: NextRequest) {
|
||||||
const { pathname } = request.nextUrl;
|
const { pathname } = request.nextUrl;
|
||||||
const isPublic =
|
const isPublic =
|
||||||
pathname === "/login" ||
|
pathname === "/login" ||
|
||||||
Reference in New Issue
Block a user