clerk / clerk/javascript

`useUser` has a differently typed user object than `currentUser` and `clerkClient.users.getUser`

Aperta
#2,176 10 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

prioritized
Lingua principale
TypeScript
Stelle
1.8k
Fork
472
Merge medio
2g 11h
PR unite (30g)
189

Descrizione

Preliminary Checks
Reproduction / Replay Link

https://github.com/clerk/javascript/blob/main/packages/nextjs/src/app-router/server/currentUser.ts#L6

Publishable key

pk_test_1234567890

Description

When developing with Clerk the user objects returned from useUser() and currentUser() are different. Notably primaryEmailAddress and fullName exists in useUser().user, but doesn't exist in currentUser(). This inconsistency makes it more difficult to create shared utils and generally share things across different parts of our application.

The docs claim that these are the same User object, but that is not accurate.

The currentUser helper returns the User object of the currently active user. This is the same User object that is returned by the useUser hook.

The deviation occurs because useUser from clerk-react users clerk-types/UserResource: https://github.com/clerk/javascript/blob/main/packages/react/src/hooks/useUser.ts#L1

And currentUser uses clerk-backend/User: https://github.com/clerk/javascript/blob/main/packages/nextjs/src/app-router/server/currentUser.ts#L1

Expected behavior:

useUser().user and currentUser() should be the same type

Actual behavior:

They are not the same type

Environment
Not relevant and hard to get correct packages from a mono repo, but here it is for the root:


  System:
    OS: macOS 14.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 53.19 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.3.1 - ~/.nvm/versions/node/v20.3.1/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v20.3.1/bin/npm
    pnpm: 8.10.0 - ~/.nvm/versions/node/v20.3.1/bin/pnpm
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 17.1
  npmPackages:
    @babel/preset-typescript: ^7.22.15 => 7.22.15
    @commitlint/cli: ^17.6.7 => 17.6.7
    @commitlint/config-conventional: ^17.6.7 => 17.6.7
    @knnlabs/configs: workspace:* => 0.0.0
    @knnlabs/eslint-config-custom: workspace:* => 0.0.0
    @trivago/prettier-plugin-sort-imports: ^4.2.0 => 4.2.0
    @turbo/gen: ^1.10.12 => 1.10.12
    @types/jest: ^29.5.4 => 29.5.4
    bun: ^1.0.3 => 1.0.3
    eslint: ^8.46.0 => 8.50.0
    husky: ^8.0.3 => 8.0.3
    jest: ^29.6.4 => 29.6.4
    lint-staged: ^13.2.3 => 13.2.3
    prettier: ^3.0.0 => 3.0.0
    prettier-plugin-prisma: ^5.0.0 => 5.0.0
    turbo: ^1.10.16 => 1.10.16

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia confrontando i tipi usati in packages/react/src/hooks/useUser.ts e packages/nextjs/src/app-router/server/currentUser.ts, come indicato nel report. Il lavoro è completato quando useUser().user e currentUser() espongono lo stesso tipo User, incluse proprietà come primaryEmailAddress e fullName, in modo coerente con la documentazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
nextjs, react, typescript
Ambito
authentication, backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.