Skip to content

Bug: SDK advertises isLoading false before it fully resolves with user and authenticated status #431

@jonschmidt

Description

@jonschmidt

Prerequisites

Describe the issue

Expected behavior (per Kinde docs): When isLoading is false, the isAuthenticated value should be reliable.

Actual behavior: There's a transient state where isLoading: false, isAuthenticated: false, user: null appears briefly before the correct state isLoading: false, isAuthenticated: true, user: {...}.

Root cause (from SDK source analysis):

  1. KindeProvider wraps the React SDK's KindeProvider with forceChildrenRender: true
  2. useKindeBrowserClient → useProvidedKindeAuth calls transformReactAuthStateToNextState(reactState) which is async (decodes JWT tokens)
  3. The transform reads isLoading directly from the React SDK state
  4. But user depends on the async token decoding completing
  5. Result: React SDK's isLoading: false propagates immediately, but user (and thus isAuthenticated) remains null until the async transform completes

Location in SDK:

  • dist/src/frontend/hooks/public/use-provided-kinde-auth.cjs.js
  • dist/src/frontend/factories/index.cjs.js - transformReactAuthStateToNextState always sets isAuthenticated: false, then constructKindeClientState derives it from !!user

Here are some logs that illustrate the order we get

useAuthProvider.ts:25 [Kinde SDK State] {isLoading: true, isAuthenticated: false, hasUser: false}
useAuthProvider.ts:25 [Kinde SDK State] {isLoading: true, isAuthenticated: false, hasUser: false}
useAuthProvider.ts:25 [Kinde SDK State] {isLoading: false, isAuthenticated: false, hasUser: false}
useAuthProvider.ts:25 [Kinde SDK State] {isLoading: false, isAuthenticated: false, hasUser: false}
useAuthProvider.ts:25 [Kinde SDK State] {isLoading: false, isAuthenticated: true, hasUser: true}

Library URL

https://github.com/kinde-oss/kinde-auth-nextjs/

Library version

2.11.0

Operating system(s)

macOS

Operating system version(s)

Sonoma 14.5

Further environment details

No response

Reproducible test case URL

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions