Zambla
Zambla
Explore posts from servers
BABetter Auth
Created by Zambla on 4/8/2025 in #help
Basic Authentication with Caddy
I serve my app with Caddy and I have a set Basic Authentication in my Caddyfile :
example.com {
basic_auth {
# Username "Bob", password "hiccup"
Bob $2a$14$Zkx19XLiW6VYouLHR5NmfOFU0z2GTNmpkT/5qqR7hx4IjWJPDhjvG
}
reverse_proxy app:3000
}
example.com {
basic_auth {
# Username "Bob", password "hiccup"
Bob $2a$14$Zkx19XLiW6VYouLHR5NmfOFU0z2GTNmpkT/5qqR7hx4IjWJPDhjvG
}
reverse_proxy app:3000
}
The authentication works (with both Basic auth and better-auth). But when I try to create a new user, I get a 404 Unauthorized response with this header in the response :
{
'alt-svc': 'h3=":443"; ma=2592000',
server: 'Caddy',
'www-authenticate': 'Basic realm="restricted"',
date: 'Tue, 08 Apr 2025 16:25:37 GMT',
'content-length': '0'
}
{
'alt-svc': 'h3=":443"; ma=2592000',
server: 'Caddy',
'www-authenticate': 'Basic realm="restricted"',
date: 'Tue, 08 Apr 2025 16:25:37 GMT',
'content-length': '0'
}
However, when I remove the basic_auth part from my Caddyfile, it works great. This is my auth.ts:
import {betterAuth, BetterAuthOptions} from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db/drizzle";
import {admin, customSession} from "better-auth/plugins";

const options = {
database: drizzleAdapter(db, {
provider: "pg",
}),
plugins: [
admin(),
],
emailAndPassword: {
enabled: true
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60
}
},
} satisfies BetterAuthOptions;

export const auth = betterAuth({
...options,
plugins: [
...(options.plugins ?? []),
customSession(async ({ user, session }) => {
return {
user,
session
}
}, options),
]
});
import {betterAuth, BetterAuthOptions} from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db/drizzle";
import {admin, customSession} from "better-auth/plugins";

const options = {
database: drizzleAdapter(db, {
provider: "pg",
}),
plugins: [
admin(),
],
emailAndPassword: {
enabled: true
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60
}
},
} satisfies BetterAuthOptions;

export const auth = betterAuth({
...options,
plugins: [
...(options.plugins ?? []),
customSession(async ({ user, session }) => {
return {
user,
session
}
}, options),
]
});
My auth-client.ts:
import { createAuthClient } from "better-auth/react"
import {adminClient} from "better-auth/client/plugins";

export const authClient = createAuthClient({
plugins: [
adminClient(),
],
})
import { createAuthClient } from "better-auth/react"
import {adminClient} from "better-auth/client/plugins";

export const authClient = createAuthClient({
plugins: [
adminClient(),
],
})
And this is how I create a new user :
await authClient.signUp.email({
name: "test",
password: "password",
})
await authClient.signUp.email({
name: "test",
password: "password",
})
How can I make this work? Do I need to add basic authentication somewhere in my better-auth configuration?
5 replies
RRunPod
Created by Zambla on 1/30/2025 in #⚡|serverless
How much does it cost to use multi-GPU ?
No description
6 replies