Skip to content
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

Chore: Implement naming convention for createClient functions #547

Merged
merged 2 commits into from
May 18, 2023

Conversation

dijonmusters
Copy link
Contributor

@dijonmusters dijonmusters commented May 17, 2023

What kind of change does this PR introduce?

Chore

What is the current behavior?

  1. createClient functions do not follow a clear convention
  2. pages directory createClient functions are the default - no longer the recommended path

What is the new behavior?

The App Router createClient functions follow a contextual convention as to where they are being used:

  • createClientComponentClient
  • createServerComponentClient
  • createMiddlewareClient
  • createRouteHandlerClient
  • createServerActionClient

Pages directory createClient functions now contain pages in their name

  • createPagesBrowserClient
  • createPagesServerClient

Have also removed the Supabase part of each export, as this feels unnecessary.

Additional context

We cannot consolidate all server-side functions into a single createServerClient function, as Server Components will not be able to set cookies, therefore, will always need to use middleware to refresh expired sessions: vercel/next.js#41745 (reply in thread)

While createRouteHandlerClient and createServerActionClient are exactly the same function, I think it best to keep these as separate exports to simplify the DX when consuming them - if they were named the same, I think it would cause more confusion and require an unnecessarily deep understanding of the design decisions of the Next.js App Router.

This same justification goes for createPagesBrowserClient and createClientComponentClient. Having this clear separation between pages and App Router simplifies the DX.

@dijonmusters dijonmusters changed the base branch from main to next May 17, 2023 02:38
Copy link
Member

@thorwebdev thorwebdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@silentworks silentworks merged commit d90866f into next May 18, 2023
@silentworks silentworks deleted the chore/rename-create-client-functions branch May 18, 2023 01:30
@dijonmusters
Copy link
Contributor Author

Awesome work! Thanks @silentworks! 🙌

silentworks added a commit that referenced this pull request May 25, 2023
* Update changeset config and git workflow

* Update to ci pipeline latest LTS nodejs

* Storage adapter (#507)

* add storage adapters

* Remove unused filterCookies function

* add pkce support

* update sveltekit example

* Add pre-release changeset

* Bump SvelteKit version

---------

Co-authored-by: David Plugge <[email protected]>

* chore: update versions (next) (#508)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* simplifying defaults for storage adapter (#510)

* chore: update versions (next) (#511)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* remove unused type (#512)

* remove unused type

* add changeset

* chore: update versions (next) (#513)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* chore: add jose to .next branch (#526)

* Add jose for it's base64url decode support

* Remove js-base64 becuase buffer check Vercel issue

* chore: update versions (next) (#527)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Fix Failed to parse cookie string in middleware (#532)

* chore: update versions (next) (#533)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix cookie saving in middleware/routeHandler (#536)

* chore: update versions (next) (#537)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* add lint and format scripts (#538)

* change prettier config
* format md files with spaces
* add husky and pre-commit script
* add lint-staged
* configure lint-staged
* use tsc as linter
* add ci workflow
* add checks permission
* use prettierignore

* WIP: Writable cookies (#543)

* wip: example for writable cookies - server actions and route handlers

* add ReadonlyRequestCookies type for Server Component client

* swap routeHandler and serverActions client (#544)

* Chore: Implement naming convention for createClient functions (#547)

* implement consistent naming convention for createClient functions

* Add deprecated functions and changeset

---------

Co-authored-by: Andrew Smith <[email protected]>

* chore: update versions (next) (#548)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Ignore changeset and github actions

* Chore: Implement singleton pattern for createClientComponentClient function (#550)

* implement singleton pattern for createClientComponentClient

* Fix type issue (#554)

* Fix: Set response cookie (#551)

* add cookie header to make refreshed session available in Server Components

* add guard around setting headers

* Chore: Update Next.js and remove custom type for WritableCookies (#552)

* update next.js and remove custom type

* chore: update versions (next) (#555)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Fix: Typedefs for clientClient functions (#556)

* add explicit return types for createClient functions

* add deprecated functions for App Router createClient functions

* add changeset

* Fix: missing type from SvelteKit and remix package (#557)

* chore: update versions (next) (#558)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Final release of auth-helpers PKCE

* chore: update versions (#559)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: David Plugge <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: David Plugge <[email protected]>
Co-authored-by: Jon Meyers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants