I am gettng internal server error and not understanding why, how to get logs

anyway to debug this?
GET http://localhost:3000/api/auth/get-session 500 (Internal Server Error)
GET http://localhost:3000/api/auth/get-session 500 (Internal Server Error)
Solution:
That line is outputting the result of a GET request I would imagine the 500 is emitting some error to the log server-side? Are you sure there's nothing else in your console? You could try adding logging to your Next.js API route handler like this and interrogating the request to see if anything looks odd: ...
Jump to solution
5 Replies
whizzy
whizzyOP3mo ago
@Ping you know anything about this?
Ping
Ping3mo ago
Can I see your auth config?
whizzy
whizzyOP3mo ago
import { database } from '@delulu/database';
import { resend } from '@delulu/email';
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { keys } from './keys';

export const auth = betterAuth({
database: drizzleAdapter(database, {
provider: 'pg',
}),
emailVerification: {
async sendVerificationEmail({ user, url }) {
await resend.emails.send({
from: 'Delulu Social <noreply@delulu.social>',
to: user.email,
subject: 'Verify Your Email Address',
html: `
// some html
`,
});
},
},
emailAndPassword: {
enabled: true,
sendResetPassword: async ({ user, url }) => {
await resend.emails.send({
from: 'Delulu Social <noreply@delulu.social>',
to: user.email,
subject: 'Reset Your Password',
html: `
//some html

`,
});
},
},
socialProviders: {
google: {
clientId: keys().GOOGLE_CLIENT_ID,
clientSecret: keys().GOOGLE_CLIENT_SECRET,
},
},
account: {
accountLinking: {
enabled: true,
trustedProviders: ['google'],
updateUserInfoOnLink: true,
},
},
});
import { database } from '@delulu/database';
import { resend } from '@delulu/email';
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { keys } from './keys';

export const auth = betterAuth({
database: drizzleAdapter(database, {
provider: 'pg',
}),
emailVerification: {
async sendVerificationEmail({ user, url }) {
await resend.emails.send({
from: 'Delulu Social <noreply@delulu.social>',
to: user.email,
subject: 'Verify Your Email Address',
html: `
// some html
`,
});
},
},
emailAndPassword: {
enabled: true,
sendResetPassword: async ({ user, url }) => {
await resend.emails.send({
from: 'Delulu Social <noreply@delulu.social>',
to: user.email,
subject: 'Reset Your Password',
html: `
//some html

`,
});
},
},
socialProviders: {
google: {
clientId: keys().GOOGLE_CLIENT_ID,
clientSecret: keys().GOOGLE_CLIENT_SECRET,
},
},
account: {
accountLinking: {
enabled: true,
trustedProviders: ['google'],
updateUserInfoOnLink: true,
},
},
});
Solution
Alex Booker
Alex Booker3mo ago
That line is outputting the result of a GET request I would imagine the 500 is emitting some error to the log server-side? Are you sure there's nothing else in your console? You could try adding logging to your Next.js API route handler like this and interrogating the request to see if anything looks odd:
import { auth } from '@/auth-server'
import { toNextJsHandler } from 'better-auth/next-js'

const { POST: originalPOST, GET: originalGET } = toNextJsHandler(auth)

export const POST = async (req: Request) => {
console.log('POST request to auth endpoint', req.url)
return originalPOST(req)
}

export const GET = async (req: Request) => {
console.log('GET request to auth endpoint', req.url)
return originalGET(req)
}
import { auth } from '@/auth-server'
import { toNextJsHandler } from 'better-auth/next-js'

const { POST: originalPOST, GET: originalGET } = toNextJsHandler(auth)

export const POST = async (req: Request) => {
console.log('POST request to auth endpoint', req.url)
return originalPOST(req)
}

export const GET = async (req: Request) => {
console.log('GET request to auth endpoint', req.url)
return originalGET(req)
}
It's hard to help without more details. What action do you take to trigger the error?
whizzy
whizzyOP3mo ago
actually its fixed idk the reason, but it seems to be fixed, I moved from prisma to drizzle anyway thanks for the help this would help with logging anyway

Did you find this page helpful?