Skip to content

feat(nextjs): Support Keyless mode #4602

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

Merged
merged 35 commits into from
Dec 5, 2024

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Nov 19, 2024

Description

Opt-in support for Keyless

This is introduced for @clerk/nextjs but more sdks may follow in the future.

What does the PR do (for development only).

  • Allows for a Clerk Next.js application to run without publishable and secret keys being explicitly set.
  • It will automatically creates new keys and stores them inside .clerk/
  • The application will use those keys, but prompts the user to claim them.

Technical

  • For ClerkProvider as RSC: clerkMIddleware detects missing sk -> basically calls next() as "signed-out" and let rendering to call Server ClerkProvider -> Server ClerkProvider fetches and creates the keys, stores them into a file -> It passes the keys into a client component that will fire a server action on mount that sets the keys into cookies and redirect to a made up url that clerkMiddelware expects -> clerkMiddleware runs again, this time detects the cookies that contain the accountless keys and properly propagates the pk and sk further down.

  • For ClerkProvider as Client component: The provider will render which fires a server action that creates the keys and set them into cookies. Once this is completed we return only the PK and the claimUrl and we force the ClerkProvider from clerk-react to remount.

Requirements

  • Store the keys in the file system, in order for the keys to "belong" to a certain project.
  • Use hashed cookies based on the working directory (PWD) of the project to allow multiple projects that run in accountless project to work.
  • We are using cookies as a way of syncing the rendering lifecycle with the middleware.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Nov 19, 2024

🦋 Changeset detected

Latest commit: b04a9d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@clerk/backend Minor
@clerk/clerk-react Minor
@clerk/nextjs Minor
@clerk/clerk-js Minor
@clerk/types Minor
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nuxt Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/tanstack-start Patch
@clerk/testing Patch
@clerk/chrome-extension Patch
@clerk/elements Patch
@clerk/clerk-expo Patch
@clerk/expo-passkeys Patch
@clerk/localizations Patch
@clerk/shared Patch
@clerk/themes Patch
@clerk/ui Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@panteliselef panteliselef self-assigned this Nov 19, 2024
…der and update middleware to read sk and pk from cookies
Copy link

vercel bot commented Nov 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ⬜️ Skipped (Inspect) Dec 5, 2024 3:33pm

@panteliselef panteliselef force-pushed the elef/user-1072-support-accountless-in-clerknextjs branch from 18e8fe4 to 5e0181d Compare November 21, 2024 11:49
React does not like the fact that <html><body> may be missing and that Suspense is not used inside <html>
@panteliselef panteliselef marked this pull request as draft November 21, 2024 13:45
Copy link
Member

@brkalow brkalow left a comment

Choose a reason for hiding this comment

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

👏 left a few minor comments, but functionally I think this is good to go! Nice job

…s-in-clerknextjs

# Conflicts:
#	packages/nextjs/src/app-router/server/ClerkProvider.tsx
@panteliselef panteliselef merged commit 3f64080 into main Dec 5, 2024
27 checks passed
@panteliselef panteliselef deleted the elef/user-1072-support-accountless-in-clerknextjs branch December 5, 2024 15:41
wobsoriano pushed a commit that referenced this pull request Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants