[GH-ISSUE #903] Error when trying to get session on client component using useSession in Next.js 15.1 #8492

Closed
opened 2026-04-13 03:34:19 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @kaitakami on GitHub (Dec 16, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/903

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Start a project with next.js 15.1
  2. Set up better auth client components
  3. Try getting session with useSession hook
import { useSession } from "@/lib/auth-client"

export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
  const { data: session, isPending } = useSession()
  const user = session?.user

  return (
    // ...
  )

// ...

You will get:

This expression is not callable.
  No constituent of type 'Atom<{ data: { user: { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; banned: boolean | null | undefined; role?: string | ... 1 more ... | undefined; banReason?: string | ... 1 more ... | undefined; banExpires?: Date | ... 1 more ...' is callable.ts(2349)

Current vs. Expected behavior

We expect to get the user session.

The current behaviour is that error, and session won't load on the frontend.

image

What version of Better Auth are you using?

1.0.21

Provide environment information

- OS: MacOS
- Browser: Chrome
- Runtime: node.js v22

package.json:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev --turbopack",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@radix-ui/react-avatar": "^1.1.2",
    "@radix-ui/react-checkbox": "^1.1.3",
    "@radix-ui/react-collapsible": "^1.1.2",
    "@radix-ui/react-dialog": "^1.1.3",
    "@radix-ui/react-dropdown-menu": "^2.1.3",
    "@radix-ui/react-label": "^2.1.1",
    "@radix-ui/react-separator": "^1.1.1",
    "@radix-ui/react-slot": "^1.1.1",
    "@radix-ui/react-tooltip": "^1.1.5",
    "@react-three/fiber": "^8.17.10",
    "@types/three": "^0.171.0",
    "better-auth": "^1.0.21",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "framer-motion": "^11.14.4",
    "lucide-react": "^0.468.0",
    "next": "15.1.0",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "tailwind-merge": "^2.5.5",
    "tailwindcss-animate": "^1.0.7",
    "three": "^0.171.0"
  },
  "devDependencies": {
    "@better-auth/cli": "^1.0.21",
    "@types/node": "^20",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }
}

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import { createAuthClient } from "better-auth/client"
import { organizationClient, adminClient } from "better-auth/client/plugins"

export const authClient = createAuthClient({
    baseURL: "http://localhost:9999",
    appName: "",
    plugins: [
        organizationClient(),
        adminClient(),
    ],
})

export const {
    signIn,
    signOut,
    signUp,
    useSession,
    updateUser,
    getSession,
    useListOrganizations,
    useActiveOrganization,
} = authClient;

Additional context

No response

Originally created by @kaitakami on GitHub (Dec 16, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/903 ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce 1. Start a project with next.js 15.1 2. Set up better auth client components 3. Try getting session with `useSession` hook ```ts import { useSession } from "@/lib/auth-client" export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) { const { data: session, isPending } = useSession() const user = session?.user return ( // ... ) // ... ``` You will get: ``` This expression is not callable. No constituent of type 'Atom<{ data: { user: { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; banned: boolean | null | undefined; role?: string | ... 1 more ... | undefined; banReason?: string | ... 1 more ... | undefined; banExpires?: Date | ... 1 more ...' is callable.ts(2349) ``` ### Current vs. Expected behavior We expect to get the user session. The current behaviour is that error, and session won't load on the frontend. <img width="401" alt="image" src="https://github.com/user-attachments/assets/1b49d83e-a3fd-431d-aba6-09c9eafbdd68" /> ### What version of Better Auth are you using? 1.0.21 ### Provide environment information ```bash - OS: MacOS - Browser: Chrome - Runtime: node.js v22 package.json: { "name": "frontend", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev --turbopack", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@radix-ui/react-avatar": "^1.1.2", "@radix-ui/react-checkbox": "^1.1.3", "@radix-ui/react-collapsible": "^1.1.2", "@radix-ui/react-dialog": "^1.1.3", "@radix-ui/react-dropdown-menu": "^2.1.3", "@radix-ui/react-label": "^2.1.1", "@radix-ui/react-separator": "^1.1.1", "@radix-ui/react-slot": "^1.1.1", "@radix-ui/react-tooltip": "^1.1.5", "@react-three/fiber": "^8.17.10", "@types/three": "^0.171.0", "better-auth": "^1.0.21", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "framer-motion": "^11.14.4", "lucide-react": "^0.468.0", "next": "15.1.0", "react": "^19.0.0", "react-dom": "^19.0.0", "tailwind-merge": "^2.5.5", "tailwindcss-animate": "^1.0.7", "three": "^0.171.0" }, "devDependencies": { "@better-auth/cli": "^1.0.21", "@types/node": "^20", "@types/react": "^19", "@types/react-dom": "^19", "postcss": "^8", "tailwindcss": "^3.4.1", "typescript": "^5" } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { createAuthClient } from "better-auth/client" import { organizationClient, adminClient } from "better-auth/client/plugins" export const authClient = createAuthClient({ baseURL: "http://localhost:9999", appName: "", plugins: [ organizationClient(), adminClient(), ], }) export const { signIn, signOut, signUp, useSession, updateUser, getSession, useListOrganizations, useActiveOrganization, } = authClient; ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 03:34:19 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 16, 2024):

import { createAuthClient } from "better-auth/client"

this should be imported from react instead

import { createAuthClient } from "better-auth/react"
<!-- gh-comment-id:2544630868 --> @Bekacru commented on GitHub (Dec 16, 2024): ```ts import { createAuthClient } from "better-auth/client" ``` this should be imported from react instead ```ts import { createAuthClient } from "better-auth/react" ```
Author
Owner

@kaitakami commented on GitHub (Dec 16, 2024):

😝 Thank you @Bekacru

<!-- gh-comment-id:2544653359 --> @kaitakami commented on GitHub (Dec 16, 2024): 😝 Thank you @Bekacru
Author
Owner

@barrynorman commented on GitHub (Apr 24, 2025):

made my day. thanks.

<!-- gh-comment-id:2828747215 --> @barrynorman commented on GitHub (Apr 24, 2025): made my day. thanks.
Author
Owner

@sf1tzp commented on GitHub (Jan 22, 2026):

Similarly for svelte projects:

import { createAuthClient } from "better-auth/svelte";
<!-- gh-comment-id:3787451464 --> @sf1tzp commented on GitHub (Jan 22, 2026): Similarly for svelte projects: ``` import { createAuthClient } from "better-auth/svelte"; ```
Author
Owner

@github-actions[bot] commented on GitHub (Apr 1, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4166563274 --> @github-actions[bot] commented on GitHub (Apr 1, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8492