Skip to content

Invalid Origin (v0.7) #45

Description

@mrekh

I'm encountering an "Invalid Origin" error when using Better Auth component (v0.7.12) in my application. Based on the documentation, this version should not have CORS issues.

Setup:

In lib/auth.ts, I've implemented the provided code from the documentation, updating it to utilize an environment variable (NEXT_PUBLIC_SITE_URL) for siteUrl:

import { type GenericCtx } from "@convex/_generated/server";
import { betterAuthComponent } from "@convex/auth";

import { convexAdapter } from "@convex-dev/better-auth";
import { convex } from "@convex-dev/better-auth/plugins";
import { betterAuth } from "better-auth";

// You'll want to replace this with an environment variable
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL;

export const createAuth = (ctx: GenericCtx) =>
	// Configure your Better Auth instance here
	betterAuth({
		// All auth requests will be proxied through your next.js server
		baseURL: siteUrl,
		database: convexAdapter(ctx, betterAuthComponent),

		// Simple non-verified email/password to get started
		emailAndPassword: {
			enabled: true,
			requireEmailVerification: false,
		},
		plugins: [
			// The Convex plugin is required
			convex(),
		],
	});

Problem:

When attempting to sign up on my Vercel production domain, the "Invalid Origin" error appears. Simultaneously, my Convex dashboard displays a corresponding error. The NEXT_PUBLIC_SITE_URL environment variable is correctly set in my Vercel environment.

Image

Suspected Cause & Suggestion:

This appears to be a bug. If not, it would be beneficial to add a section to the documentation instructing users to set trustedOrigins in their createAuth configuration to prevent this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions