admin管理员组文章数量:1323226
I'm trying to know if a user is banned from my middleware and redirect it to a custom error page. The problems happens when I make the query to the DB from Drizzle ORM, I have created an async function to select the user sanction but at the moment of use the value returned from my function the server throw this cryptic error:
GET / 404 in 52ms
GET /favicon.ico 200 in 1909ms
✓ Compiled middleware in 217ms
⨯ [Error [TypeError]: Unsupported type of value]
✓ Compiled in 20ms
GET / 404 in 31ms
GET /favicon.ico 200 in 431ms
this is my middleware:
import { auth } from "@/auth"
import type { NextRequest } from "next/server"
import { checkIsBanned } from "./lib/utils"
export const config = {
matcher: ["/feed(.*)", "/posts(.*)", "/shop(.*)", "/"],
}
export async function middleware(req: NextRequest) {
const userSession = await auth();
const userIsBanned = await checkIsBanned(userSession?.user?.id as string)
if (userIsBanned) {
console.log("user is banned")
const bannedPage = new URL("/banned", req.nextUrl.origin);
return Response.redirect(bannedPage);
}
}
and the function to check if the user is banned:
import { db } from "@/db";
import { type SelectSanction, sanctions } from "@/db/schema";
import { and, eq, lt } from "drizzle-orm";
export async function checkIsBanned(userId: string) {
const currentDate = new Date()
const sanctionsApplied: SelectSanction[] = await db.select()
.from(sanctions)
.where(and(eq(sanctions.userId, userId), lt(sanctions.endDate, currentDate)));
console.log(sanctionsApplied)
return sanctionsApplied.length > 0;
}
I have tried to find info in google but it seems to be a particular case and just expect to receive a boolean indicating if the user is banned or not
I'm using Next 15 + drizzleORM + libsql
本文标签: typescriptUnsupported type of value in NextjsStack Overflow
版权声明:本文标题:typescript - Unsupported type of value in Nextjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742087420a2420063.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论