-
Notifications
You must be signed in to change notification settings - Fork 279
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(nextjs): Improve experience when swapping keys on Keyless mode #4787
chore(nextjs): Improve experience when swapping keys on Keyless mode #4787
Conversation
🦋 Changeset detectedLatest commit: 9c2caa2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
/** | ||
* There is a great chance when running on Keyless mode that the above fails, | ||
* because the keys hot-swapped and the Next.js dev server has not yet fully rebuilt middleware and routes. | ||
* | ||
* Attempt one more time with the default dummy value. | ||
*/ | ||
if (canUseKeyless__server) { | ||
try { | ||
return decryptData(encryptedRequestData, KEYLESS_ENCRYPTION_KEY); | ||
} catch (e) { | ||
throwInvalidEncryptionKey(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple retrying with the dummy value
.changeset/young-beans-trade.md
Outdated
'@clerk/nextjs': patch | ||
--- | ||
|
||
Improve experience when swapping keys on Keyless mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Should we mention here regarding the hot-swapped .env case? Just to clarify the "improve experience" part
.changeset/young-beans-trade.md
Outdated
'@clerk/nextjs': patch | ||
--- | ||
|
||
Improve experience when swapping keys on Keyless mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve experience when swapping keys on Keyless mode. | |
Improve error message when swapping keys defined as environment variables. Affects (code=encryption_key_invalid). | |
**On Keyless mode**: Attempt to not throw the error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BRKalow @LauraBeatris is this better ?
Co-authored-by: Bryce Kalow <[email protected]>
Co-authored-by: Bryce Kalow <[email protected]>
…laiming-the-keys-and-adding
Description
In Keyless mode it is expected that the user will eventually set keys as environment variables. When they do that, the nextjs server will restart, but there seems to be a mismatch because first the rendering lifecycle runs with the new keys and then the keys are updated in the middleware. This causes an error to be thrown to the user which we can actually improve.
For the happy path: we avoid displaying that error by retrying to decrypt data with the dummy key.
For any other case: when swapping keys or going back to headless you will now see this (see picture). this does not only reply to keyless.
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change