Skip to content

Commit

Permalink
♻️ use isBot utility provided by next instead of isbot package
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredkiss3 committed Jan 12, 2024
1 parent 04d0b44 commit fbaa4f4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { NextRequest, NextResponse } from "next/server";
import { NextRequest, NextResponse, userAgent } from "next/server";
import {
GITHUB_AUTHOR_USERNAME,
GITHUB_REPOSITORY_NAME,
SESSION_COOKIE_KEY
} from "./lib/shared/constants";
import { Session } from "./lib/server/session.server";
import isbot from "isbot";

import type { ResponseCookie } from "next/dist/compiled/@edge-runtime/cookies";

Expand Down Expand Up @@ -64,7 +63,8 @@ export default async function middleware(request: NextRequest) {
// Ensure a session is attached to each user
const sessionId = request.cookies.get(SESSION_COOKIE_KEY)?.value;
let session = sessionId ? await Session.get(sessionId) : null;
const isBot = isbot(request.headers.get("User-Agent"));
const { isBot } = userAgent(request);
console.log({ isBot });
if (!session) {
session = await Session.create(isBot);
return setRequestAndResponseCookies(request, session.getCookie());
Expand Down

0 comments on commit fbaa4f4

Please sign in to comment.