-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
26 lines (23 loc) · 730 Bytes
/
auth.js
File metadata and controls
26 lines (23 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import NextAuth from 'next-auth'
import { getUser } from 'lib/db'
import { sendEvent } from 'lib/ga'
import authConfig from './auth.config'
export const { auth, handlers, signIn, signOut } = NextAuth({
...authConfig,
callbacks: {
async jwt({ token, account, user }) {
if (account)
token.visitor = await getUser(account.providerAccountId, account.provider, user)
return token
},
session({ session, token }) {
session.user = { ...session.user, ...token.visitor }
return session
}
},
events: {
async signIn({ account }) {
await sendEvent('login', { 'method': account.provider })
}
}
})