fix: app name shouldn't be used to prefix cookies (#447)

This commit is contained in:
Bereket Engida
2024-11-07 16:09:22 +03:00
committed by GitHub
parent a94623da29
commit 2ba2bec1f1
3 changed files with 3 additions and 3 deletions

View File

@@ -23,6 +23,7 @@ const libsql = new LibsqlDialect({
}); });
export const auth = betterAuth({ export const auth = betterAuth({
appName: "Better Auth Demo",
database: { database: {
dialect: libsql, dialect: libsql,
type: "sqlite", type: "sqlite",

View File

@@ -7,7 +7,7 @@ Cookies are used to store data such as session tokens, OAuth state, and more. Al
### Cookie Prefix ### Cookie Prefix
Better Auth cookies will follow `${prefix}.${cookie_name}` format by default. The prefix equals to the `appName` provided in the auth options by default. If not provided, the prefix will be "better-auth". You can change the prefix by setting `cookiePrefix` in the `advanced` object of the auth options. Better Auth cookies will follow `${prefix}.${cookie_name}` format by default. The prefix will be "better-auth" by default. You can change the prefix by setting `cookiePrefix` in the `advanced` object of the auth options.
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"

View File

@@ -31,8 +31,7 @@ export function createCookieGetter(options: BetterAuthOptions) {
cookieName: string, cookieName: string,
overrideAttributes: Partial<CookieOptions> = {}, overrideAttributes: Partial<CookieOptions> = {},
) { ) {
const prefix = const prefix = options.advanced?.cookiePrefix || "better-auth";
options.advanced?.cookiePrefix || options.appName || "better-auth";
const name = const name =
options.advanced?.cookies?.[cookieName as "session_token"]?.name || options.advanced?.cookies?.[cookieName as "session_token"]?.name ||
`${prefix}.${cookieName}`; `${prefix}.${cookieName}`;