Postgres
This commit is contained in:
@@ -9,7 +9,7 @@ import { headers } from 'next/headers'
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: prismaAdapter(prisma, {
|
||||
provider: 'sqlite',
|
||||
provider: 'postgresql',
|
||||
}),
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
@@ -17,13 +17,13 @@ export const auth = betterAuth({
|
||||
secret: process.env.BETTER_AUTH_SECRET!,
|
||||
baseURL: process.env.BETTER_AUTH_URL!,
|
||||
trustedOrigins: [
|
||||
process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3032',
|
||||
process.env.EXPO_PUBLIC_API_URL ?? 'http://localhost:3032',
|
||||
process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3010',
|
||||
process.env.EXPO_PUBLIC_API_URL ?? 'http://localhost:3010',
|
||||
'http://localhost:3000',
|
||||
'http://localhost:3001',
|
||||
'http://localhost:3032',
|
||||
'http://localhost:3010',
|
||||
'http://localhost:8081',
|
||||
'http://*.localhost:3032',
|
||||
'http://*.localhost:3010',
|
||||
'http://*.localhost:3000',
|
||||
'https://*.innungsapp.de',
|
||||
'https://*.innungsapp.com',
|
||||
@@ -55,17 +55,17 @@ export const auth = betterAuth({
|
||||
|
||||
export type Auth = typeof auth
|
||||
|
||||
export async function getSanitizedHeaders() {
|
||||
const allHeaders = await headers()
|
||||
const sanitizedHeaders = new Headers(allHeaders)
|
||||
export async function getSanitizedHeaders(sourceHeaders?: HeadersInit) {
|
||||
const baseHeaders = sourceHeaders ? new Headers(sourceHeaders) : new Headers(await headers())
|
||||
const sanitizedHeaders = new Headers(baseHeaders)
|
||||
|
||||
// Avoid ENOTFOUND by forcing host to localhost for internal better-auth fetches
|
||||
// We use the host defined in BETTER_AUTH_URL
|
||||
try {
|
||||
const betterAuthUrl = new URL(process.env.BETTER_AUTH_URL || 'http://localhost:3032')
|
||||
const betterAuthUrl = new URL(process.env.BETTER_AUTH_URL || 'http://localhost:3010')
|
||||
sanitizedHeaders.set('host', betterAuthUrl.host)
|
||||
} catch (e) {
|
||||
sanitizedHeaders.set('host', 'localhost:3032')
|
||||
sanitizedHeaders.set('host', 'localhost:3010')
|
||||
}
|
||||
|
||||
return sanitizedHeaders
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import nodemailer from 'nodemailer'
|
||||
|
||||
const SMTP_HOST = (process.env.SMTP_HOST ?? '').trim()
|
||||
const SMTP_HOST_IS_PLACEHOLDER = SMTP_HOST === '' || SMTP_HOST.toLowerCase() === 'smtp.example.com'
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
host: SMTP_HOST,
|
||||
port: Number(process.env.SMTP_PORT) || 587,
|
||||
secure: process.env.SMTP_SECURE === 'true',
|
||||
auth:
|
||||
@@ -10,6 +13,16 @@ const transporter = nodemailer.createTransport({
|
||||
: undefined,
|
||||
})
|
||||
|
||||
async function sendMailOrSkip(mailOptions: any, emailType: string) {
|
||||
if (SMTP_HOST_IS_PLACEHOLDER) {
|
||||
const target = typeof mailOptions?.to === 'string' ? mailOptions.to : 'unknown-recipient'
|
||||
console.warn(`[email] SMTP not configured. Skipping ${emailType} email to ${target}.`)
|
||||
return
|
||||
}
|
||||
|
||||
await transporter.sendMail(mailOptions)
|
||||
}
|
||||
|
||||
export async function sendMagicLinkEmail({
|
||||
to,
|
||||
magicUrl,
|
||||
@@ -17,7 +30,7 @@ export async function sendMagicLinkEmail({
|
||||
to: string
|
||||
magicUrl: string
|
||||
}) {
|
||||
await transporter.sendMail({
|
||||
await sendMailOrSkip({
|
||||
from: process.env.EMAIL_FROM ?? 'noreply@innungsapp.de',
|
||||
to,
|
||||
subject: 'Ihr Login-Link für InnungsApp',
|
||||
@@ -44,7 +57,7 @@ export async function sendMagicLinkEmail({
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
}, 'magic link')
|
||||
}
|
||||
|
||||
export async function sendInviteEmail({
|
||||
@@ -61,7 +74,7 @@ export async function sendInviteEmail({
|
||||
// Generate magic link for the invite
|
||||
const signInUrl = `${apiUrl}/login?email=${encodeURIComponent(to)}&invited=true`
|
||||
|
||||
await transporter.sendMail({
|
||||
await sendMailOrSkip({
|
||||
from: process.env.EMAIL_FROM ?? 'noreply@innungsapp.de',
|
||||
to,
|
||||
subject: `Einladung zur InnungsApp — ${orgName}`,
|
||||
@@ -86,7 +99,7 @@ export async function sendInviteEmail({
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
}, 'invite')
|
||||
}
|
||||
|
||||
export async function sendAdminCredentialsEmail({
|
||||
@@ -102,7 +115,7 @@ export async function sendAdminCredentialsEmail({
|
||||
password: string
|
||||
loginUrl: string
|
||||
}) {
|
||||
await transporter.sendMail({
|
||||
await sendMailOrSkip({
|
||||
from: process.env.EMAIL_FROM ?? 'noreply@innungsapp.de',
|
||||
to,
|
||||
subject: `Admin-Zugang für — ${orgName}`,
|
||||
@@ -134,5 +147,5 @@ export async function sendAdminCredentialsEmail({
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
}, 'admin credentials')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user