@@ -3,6 +3,7 @@ import { type DefaultSession, type NextAuthOptions } from "next-auth";
33import GitHubProvider from "next-auth/providers/github" ;
44import GoogleProvider from "next-auth/providers/google" ;
55
6+ import { posthog } from "@acme/api/posthog" ;
67import { prisma } from "@acme/db" ;
78
89/**
@@ -20,10 +21,13 @@ declare module "next-auth" {
2021 } & DefaultSession [ "user" ] ;
2122 }
2223
23- // interface User {
24- // // ...other properties
25- // // role: UserRole;
26- // }
24+ interface Profile {
25+ sub ?: string ;
26+ name ?: string ;
27+ email ?: string ;
28+ image ?: string ;
29+ email_verified ?: string ;
30+ }
2731}
2832
2933/**
@@ -40,6 +44,45 @@ export const authOptions: NextAuthOptions = {
4044 }
4145 return session ;
4246 } ,
47+ signIn ( { account, profile } ) {
48+ if ( account ?. provider === "google" ) {
49+ return ! ! profile ?. email_verified ;
50+ }
51+ return true ; // Do different verification for other providers that don't have `email_verified`
52+ } ,
53+ } ,
54+ events : {
55+ signIn : ( { user, account, isNewUser } ) => {
56+ posthog ?. capture ( {
57+ distinctId : user . id ,
58+ event : "signed in" ,
59+ properties : {
60+ name : user . name ,
61+ email : user . email ,
62+ provider : account ?. provider ,
63+ isNewUser,
64+ } ,
65+ } ) ;
66+ void posthog ?. shutdownAsync ( ) ;
67+ } ,
68+ signOut : ( { session } ) => {
69+ // posthog?.capture({
70+ // distinctId: session.id,
71+ // event: "logged out",
72+ // });
73+ console . log ( "add logout event" ) ;
74+ } ,
75+ createUser : ( { user } ) => {
76+ posthog ?. capture ( {
77+ distinctId : user . id ,
78+ event : "create user" ,
79+ properties : {
80+ name : user . name ,
81+ email : user . email ,
82+ } ,
83+ } ) ;
84+ void posthog ?. shutdownAsync ( ) ;
85+ } ,
4386 } ,
4487 adapter : PrismaAdapter ( prisma ) ,
4588 providers : [
@@ -63,7 +106,7 @@ export const authOptions: NextAuthOptions = {
63106 ] ,
64107 pages : {
65108 signIn : "/sign-in" ,
66- signOut : "/auth/signout" ,
67- error : "/auth/error" , // Error code passed in query string as ?error=
109+ // signOut: "/auth/signout",
110+ // error: "/auth/error", // Error code passed in query string as ?error=
68111 } ,
69112} ;
0 commit comments