Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions apps/api/src/shared/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
AUTH_ADVANCED_OPTIONS,
AUTH_API_COOKIE_PREFIX,
AUTH_APP_NAME,
AUTH_COOKIE_PREFIX,
AUTH_EMAIL_AND_PASSWORD_OPTIONS,
AUTH_SESSION_OPTIONS,
} from "@init/auth/constants"
Expand All @@ -14,10 +14,7 @@ import { ENV } from "#shared/env.generated.ts"
import { allowedOrigins, baseUrl } from "#shared/utils.ts"

export const auth = createAuth({
// The app's auth instance shares the localhost cookie jar during
// development, so this instance namespaces its cookies to keep the two
// sessions from clobbering each other.
advanced: { ...AUTH_ADVANCED_OPTIONS, cookiePrefix: `${AUTH_COOKIE_PREFIX}-api` },
advanced: { ...AUTH_ADVANCED_OPTIONS, cookiePrefix: AUTH_API_COOKIE_PREFIX },
appName: AUTH_APP_NAME,
basePath: "/auth",
baseURL: baseUrl,
Expand Down
3 changes: 3 additions & 0 deletions packages/auth/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { seconds } from "humanspan"

export const AUTH_COOKIE_PREFIX = "init"
// The API's auth instance namespaces its cookies so the two localhost jars
// stay separate during development.
export const AUTH_API_COOKIE_PREFIX = `${AUTH_COOKIE_PREFIX}-api`
export const AUTH_APP_NAME = "init"

export const AUTH_ADVANCED_OPTIONS = {
Expand Down
6 changes: 5 additions & 1 deletion packages/auth/src/expo/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { expoClient as baseExpoClient } from "@better-auth/expo/client"
import { AUTH_COOKIE_PREFIX } from "#constants.ts"
import { AUTH_API_COOKIE_PREFIX, AUTH_COOKIE_PREFIX } from "#constants.ts"

export function expoClient(opts: Parameters<typeof baseExpoClient>[0]) {
return baseExpoClient({
// Must match the API's cookie prefix: the Expo plugin only persists
// cookies whose names start with this value, and it defaults to
// "better-auth" when unset.
cookiePrefix: AUTH_API_COOKIE_PREFIX,
scheme: AUTH_COOKIE_PREFIX,
storagePrefix: AUTH_COOKIE_PREFIX,
...opts,
Expand Down