diff --git a/src/app/[locale]/api/auth/[...nextauth]/route.ts b/src/app/[locale]/api/auth/[...nextauth]/route.ts index 3e55571..4e171af 100644 --- a/src/app/[locale]/api/auth/[...nextauth]/route.ts +++ b/src/app/[locale]/api/auth/[...nextauth]/route.ts @@ -5,6 +5,7 @@ import NextAuth, { AuthOptions, Session, User } from "next-auth" import GoogleProvider from "next-auth/providers/google" import EmailProvider from "next-auth/providers/email" import { sendVerificationRequest } from "@/utils/send-verification-request" +import { trackIssue } from "@/lib/trackIssue" export const authOptions: AuthOptions = { adapter: PrismaAdapter(prisma), @@ -38,14 +39,14 @@ export const authOptions: AuthOptions = { }, events: { signIn: async ({ profile, user, isNewUser }) => { - console.log("User sign in", { ...user, isNewUser }) + trackIssue("User sign in", "info", { ...user, isNewUser }) if (!isNewUser && !user.firstName && profile?.firstName) { await updateFirstNameById(user.id, profile.firstName) } }, signOut: ({ session }) => { - console.log("User sign out", session) + trackIssue("User sign out", "info", session.user) }, }, } diff --git a/src/lib/trackIssue.ts b/src/lib/trackIssue.ts new file mode 100644 index 0000000..cbd049d --- /dev/null +++ b/src/lib/trackIssue.ts @@ -0,0 +1,23 @@ +"use server" + +const trackIssueUrl = process.env.TRACK_ISSUE_URL + +type Level = "error" | "debug" | "info" | "warn" | "fatal" + +export async function trackIssue( + message: string, + level: Level = "error", + extra?: Record +) { + if (!trackIssueUrl) return + + await fetch(trackIssueUrl, { + method: "post", + body: JSON.stringify({ + message, + level, + extra, + }), + cache: "no-cache", + }) +}