-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextdauth.ts
51 lines (49 loc) · 1.51 KB
/
nextdauth.ts
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import NextAuth from 'next-auth'
import resend from 'next-auth/providers/resend'
import google from 'next-auth/providers/google'
import github from 'next-auth/providers/github'
import passkey from 'next-auth/providers/passkey'
import { drizzleAdapter } from './adapter'
import { html, text } from './lib/auth-send-request'
import axios from 'axios'
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: drizzleAdapter,
providers: [
google,
github,
resend({
apiKey: process.env.AUTH_RESEND_KEY!,
from: '[email protected]',
async sendVerificationRequest({ identifier: email, url, provider: { from } }) {
const res = await fetch('https://api.resend.com/emails', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AUTH_RESEND_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
from,
to: email,
subject: `Sign in to Your App`,
html: html({ url, host: 'bitztech.de' }),
text: text({ url, host: 'bitztech.de' }),
}),
})
if (!res.ok) throw new Error('Resend error: ' + JSON.stringify(await res.json()))
},
}),
passkey,
],
callbacks: {
async session({ session, user }) {
session.user.id = user.id
return session
},
},
experimental: { enableWebAuthn: true },
pages: {
error: '/en/auth/error',
signIn: '/en/auth/error',
verifyRequest: '/en/auth/verify',
},
})