-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: client improvements #1428
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nextauthjs/next-auth/Canyc4LxsgLorV3dT2gvYwC2LN5f |
🎉 This PR is included in version 3.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 4.0.0-next.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
* docs(client): add TS definitions to client * docs(client): add documentation links to public methods * refactor(client): simplify window sync, simplify logic * refactor(client): extract repeating logic to _fetchData * refactor(client): remove clientId * refactor(client): use session in Provider if passed
What:
Simplify client code, and add TypeScript+JSDoc declarations.
Why:
For better DX. Also, in the process, I have been learning a lot about the choices and implementation. The bundle is also 821 bytes leaner. 🥳
How:
Abstracted away the storage syncing into a handy
BroadcastChannel
function inspired by https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API (which does not work in Safari, unfortunately 🙁 )Also removed unnecessary boolean checks in if statements, simplified if blocks, exported all user-facing API other than the
export default
keyword. (In local development, imports from "next-auth/client" did not work for some reason. Might be something with the dev app setup)the concept of
clientId
was not necessary, sincestorage
events already only listen to other window contexts. See https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_eventChecklist:
#844, #1084