Add Better Auth admin authentication
This commit is contained in:
47
tests/better-auth-env.test.ts
Normal file
47
tests/better-auth-env.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { getBetterAuthServerConfig } from "../convex/betterAuth/env";
|
||||
|
||||
test("getBetterAuthServerConfig requires BETTER_AUTH_SECRET", () => {
|
||||
assert.throws(
|
||||
() => getBetterAuthServerConfig({}),
|
||||
/Missing BETTER_AUTH_SECRET/,
|
||||
);
|
||||
});
|
||||
|
||||
test("getBetterAuthServerConfig can use a placeholder secret for schema generation", () => {
|
||||
const config = getBetterAuthServerConfig(
|
||||
{},
|
||||
{ allowMissingSecret: true },
|
||||
);
|
||||
|
||||
assert.deepEqual(config, {
|
||||
appUrl: "http://localhost:3000",
|
||||
secret: "convex-better-auth-schema-generation-secret",
|
||||
});
|
||||
});
|
||||
|
||||
test("getBetterAuthServerConfig uses BETTER_AUTH_URL before NEXT_PUBLIC_APP_URL", () => {
|
||||
const config = getBetterAuthServerConfig({
|
||||
BETTER_AUTH_SECRET: "test-secret",
|
||||
BETTER_AUTH_URL: "http://auth.local",
|
||||
NEXT_PUBLIC_APP_URL: "http://app.local",
|
||||
});
|
||||
|
||||
assert.deepEqual(config, {
|
||||
appUrl: "http://auth.local",
|
||||
secret: "test-secret",
|
||||
});
|
||||
});
|
||||
|
||||
test("getBetterAuthServerConfig falls back to local app URL", () => {
|
||||
const config = getBetterAuthServerConfig({
|
||||
BETTER_AUTH_SECRET: "test-secret",
|
||||
});
|
||||
|
||||
assert.deepEqual(config, {
|
||||
appUrl: "http://localhost:3000",
|
||||
secret: "test-secret",
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user