Skip to content

Commit

Permalink
Refactor/is bot (#127)
Browse files Browse the repository at this point in the history
* ➖ remove `isbot` dependency

* ♻️ use `isBot` utility provided by next instead of `isbot` package
  • Loading branch information
Fredkiss3 authored Jan 12, 2024
1 parent 805da75 commit fa17afe
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"eslint": "8.48.0",
"eslint-config-next": "14.0.0",
"geist": "^1.0.0",
"isbot": "^3.6.13",
"nanoid": "^4.0.2",
"next": "14.0.5-canary.38",
"nextjs-toploader": "^1.6.4",
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 fa17afe

Please sign in to comment.