Better AuthBA
Better Authβ€’10mo ago
James!

[magicLink - drizzleAdapter] The \"payload\" argument must be of type object. Received null

Hey guys, I am struggling to get to the bottom of this issue. I am hosting my backend with open-next
  • THis means that it's hosted in a lambda which shouldn't affect anything - My other DB functions work just fine.
All envvars exist
  • My implementation works locally.
  • My hosted database connection works as expected in other parts of my app
This error is haunting me. Any tips for how I can debug it?

None of the logs defined below get triggered which is weird.

return betterAuth({
secret: process.env.BETTER_AUTH_SECRET,
    logger: console,
    trustedOrigins: [getServerUrl(), '*'],
    onAPIError: {
      throw: true,
      onError(e, context) {
        console.error("[BETTER_AUTH - ERROR]", e);
        console.error("[BETTER_AUTH - CONTEXT]", context);
      }
    },

    baseURL: getServerUrl(),
// This works in my local just fine
    database: drizzleAdapter(getDrizzleDb(), {
      provider: "pg",
      usePlural: false,
      schema: {
        ...DbSchema,
        user: DbSchema.user,
      },
    }),
    plugins: [
      nextCookies(),
      magicLink({
        sendMagicLink: async ({ email, token, url }) =>
          // Send email function
      }),


I am using this better-auth version: "better-auth": "1.2.3",

Any ideas? Am I missing something?

---

Here is my /api/auth/[...all] route

The reason I have a getBetterAuth is because I am hosting on opennext & get + set the environment variables at runtime (for security purposes), so hence the reason for a function that will getBetterAuth WHEN it's needed. NOTE: I only initialize the client once, if exists, use existing, else create new client.

import { getBetterAuth } from "@/lib/auth/better-auth"; // path to your auth file
import { toNextJsHandler } from "better-auth/next-js";

export const POST = (req: Request) => {
  return toNextJsHandler(getBetterAuth()).POST(req);
};


export const GET = (req: Request) => {
return toNextJsHandler(getBetterAuth()).GET(req);
};
image.png
Was this page helpful?