Guides / Signups & Auth
NextAuth.js handles your auth, but it doesn't tell you when new users appear. You're logging in to check your database instead of getting a notification on your phone.
signIn callbackNextAuth provides lifecycle callbacks. The signIn callback fires on every login, so you can check for new users by looking at whether their account was just created.
// app/api/auth/[...nextauth]/route.ts
import NextAuth from "next-auth";
import { logit } from "@/lib/logit";
const handler = NextAuth({
providers: [
// your providers
],
callbacks: {
async signIn({ user, account, isNewUser }) {
if (isNewUser) {
await logit.now("signups", {
event: "New user signed up",
description: user.email ?? "Unknown",
icon: "๐ค",
notify: true,
tags: { provider: account?.provider ?? "unknown" },
metadata: { email: user.email, name: user.name },
});
}
return true;
},
},
});
export { handler as GET, handler as POST };
events option (v4+)In NextAuth v4, you can also use the events option which fires after successful operations:
events: {
async createUser({ user }) {
await logit.now("signups", {
event: "New user created",
description: user.email ?? "Unknown",
icon: "๐",
notify: true,
metadata: { userId: user.id, email: user.email },
});
},
},
isNewUser actually meansNote:
isNewUseris only available when using a database adapter. Without an adapter, all logins look the same โ use the database adapter and thecreateUserevent instead.
LOGIT_API_KEY=lk_live_xxxxxxxxxxxxxxxx
NEXTAUTH_SECRET=your-secret
Try LogIt free
7-day trial. No credit card required.