Skip to content

Commit

Permalink
refactor: Replace user-agent header with UserAgent from next/server
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed Sep 11, 2024
1 parent 99247a7 commit 7c5cf42
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/lib/logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sendEmail from "../sendemail";
import { render } from "@react-email/render";
import { UserActivityTemplate } from "../emails/templates";
import { UserLog } from "@models/index";
import { userAgent } from "next/server";

type userlogType = {
username: string;
Expand All @@ -16,13 +17,15 @@ async function logUserActivity(userlog: userlogType, req: Request) {
await dbConfig();

try {
const { os, browser, device } = userAgent(req);

const user_log = {
username: userlog.username,
name: userlog.name,
email: userlog.email,
action: userlog.action,
userType: userlog.role,
device: req.headers.get("user-agent") || "",
device: `${os.name} ${os.version}, ${browser.name} ${browser.version}, ${device.type}`,
ip: (req.headers.get("x-forwarded-for") ?? "127.0.0.1")
.split(",")[0]
.trim(),
Expand Down

0 comments on commit 7c5cf42

Please sign in to comment.