Skip to content
Merged
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
2 changes: 0 additions & 2 deletions docs/content/2.core-concepts/4.auto-imports-aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: What the module registers for you.
**Client**

- `useUserSession()`
- `useUserSignIn()`
- `useUserSignUp()`

**Server**

Expand Down
18 changes: 6 additions & 12 deletions docs/content/5.api/1.composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ During SSR, `updateUser` only patches local state since no client is available.
Returns per-method action handles for `useUserSession().signIn.*`. Each method exposes template-friendly async state, similar to composables like `useFetch`.

```ts [pages/login.vue]
const signIn = useUserSignIn()
const { execute, pending, status, error } = signIn.email
const { execute, pending, status, error } = useUserSignIn().email

await execute(
{ email, password, rememberMe },
Expand All @@ -153,21 +152,19 @@ await execute(
Use renaming to avoid collisions when you use multiple methods in the same scope:

```ts [pages/login.vue]
const signIn = useUserSignIn()

const {
execute: loginWithEmail,
pending: pendingEmail,
status: statusEmail,
error: errorEmail,
} = signIn.email
} = useUserSignIn().email

const {
execute: loginWithPasskey,
pending: pendingPasskey,
status: statusPasskey,
error: errorPasskey,
} = signIn.passkey
} = useUserSignIn().passkey
```

Each method returns an action handle:
Expand Down Expand Up @@ -204,8 +201,7 @@ Better Auth methods can signal failure by throwing or by resolving to a `{ error
This pattern works for both thrown errors and `{ error }` results:

```ts [pages/login.vue]
const signIn = useUserSignIn()
const { execute, status, error } = signIn.email
const { execute, status, error } = useUserSignIn().email

try {
await execute({ email, password })
Expand All @@ -224,8 +220,7 @@ if (status.value === 'error') {
If you rely on a method’s return value, you can still check for the Better Auth `{ error }` pattern:

```ts [pages/login.vue]
const signIn = useUserSignIn()
const { execute } = signIn.email
const { execute } = useUserSignIn().email

const result = await execute({ email, password })
if (result && typeof result === 'object' && 'error' in result && (result as any).error) {
Expand All @@ -238,8 +233,7 @@ if (result && typeof result === 'object' && 'error' in result && (result as any)
Same API as `useUserSignIn`, but wraps `useUserSession().signUp.*`.

```ts [pages/signup.vue]
const signUp = useUserSignUp()
const { execute, pending, status, error } = signUp.email
const { execute, pending, status, error } = useUserSignUp().email

await execute(
{ email, password, name },
Expand Down
2 changes: 1 addition & 1 deletion docs/content/5.api/3.components.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ Renders once session hydration is complete (`ready === true`) and exposes state
| `signOut` | `() => Promise<void>` | Sign out the user |

::callout{icon="i-lucide-info" to="/api/composables"}
Need `signIn` / `signUp`? Use `useUserSignIn()` / `useUserSignUp()` for template-friendly async state, or `useUserSession()` for direct access.
Need `signIn` / `signUp`? Use `useUserSession()` directly.
::
6 changes: 1 addition & 5 deletions src/runtime/app/composables/useUserSignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function createActionHandle<T extends AnyAsyncFn>(getMethod: () => T): UserAuthA
}

export function useUserSignIn(): ActionHandleMap<NonNullable<AppAuthClient>['signIn']> {
const { signIn } = useUserSession()
const handles = new Map<PropertyKey, UserAuthActionHandle<AnyAsyncFn>>()

return new Proxy({} as ActionHandleMap<NonNullable<AppAuthClient>['signIn']>, {
Expand All @@ -70,14 +69,11 @@ export function useUserSignIn(): ActionHandleMap<NonNullable<AppAuthClient>['sig
if (prop === 'then')
return undefined

// Avoid creating handles for inspection symbols.
if (typeof prop === 'symbol')
return undefined

if (handles.has(prop))
return handles.get(prop)

const handle = createActionHandle(() => {
const { signIn } = useUserSession()
return (signIn as any)[prop] as AnyAsyncFn
})

Expand Down
5 changes: 1 addition & 4 deletions src/runtime/app/composables/useUserSignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,18 @@ function createActionHandle<T extends AnyAsyncFn>(getMethod: () => T): UserAuthA
}

export function useUserSignUp(): ActionHandleMap<NonNullable<AppAuthClient>['signUp']> {
const { signUp } = useUserSession()
const handles = new Map<PropertyKey, UserAuthActionHandle<AnyAsyncFn>>()

return new Proxy({} as ActionHandleMap<NonNullable<AppAuthClient>['signUp']>, {
get(_target, prop) {
if (prop === 'then')
return undefined

if (typeof prop === 'symbol')
return undefined

if (handles.has(prop))
return handles.get(prop)

const handle = createActionHandle(() => {
const { signUp } = useUserSession()
return (signUp as any)[prop] as AnyAsyncFn
})

Expand Down
19 changes: 19 additions & 0 deletions test/cases/core-auth/server/api/test/schema.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { db } from '#auth/database'
import * as schema from '#auth/schema'

export default defineEventHandler(async () => {
const hasSchema = Boolean(schema?.user && schema?.session && schema?.account && schema?.verification)
const hasUserQuery = typeof db?.query?.user?.findMany === 'function'
let queryWorks = false

if (hasUserQuery) {
await db.query.user.findMany({ limit: 1 })
queryWorks = true
}

return {
hasSchema,
hasUserQuery,
queryWorks,
}
})
140 changes: 0 additions & 140 deletions test/use-user-signup.test.ts

This file was deleted.

Loading