fix: implement Clerk v7 custom auth flow and correct SSE parsing - #85
Merged
Conversation
This commit addresses two critical issues in the frontend functionality: 1. Authentication Flow (Clerk v7 Migration): - Migrated the custom sign-in form to utilize the correct Clerk Next.js v7 SDK API surface (`signIn.password()`, `signIn.mfa.sendEmailCode()`, `signIn.mfa.verifyEmailCode()`). - Replaced deprecated v4/v5 methods (`signIn.create`, `attemptFirstFactor`, `setActive`) which were causing TypeScript build failures. - Implemented a complete state machine to handle Multi-Factor Authentication (MFA) and Client Trust requirements, automatically toggling the UI to prompt for an email verification code when necessary. - Hardened error handling by properly casting and parsing native `ClerkError` objects without relying on deprecated array structures. 2. API Event Stream Parser: - Fixed off-by-one substring index errors in the Server-Sent Events (SSE) parser (`event:` and `data:` prefixes). - Added multiline data concatenation logic to ensure complete payload capture when streaming chunks are split across multiple lines. - Added the explicit `Accept: text/event-stream` header for better proxy/CDN compatibility. GitOrigin-RevId: 637463bdf54360d554260868c06bd0d832dc4b42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: implement Clerk v7 custom auth flow and correct SSE parsing
This commit addresses two critical issues in the frontend functionality:
Authentication Flow (Clerk v7 Migration):
signIn.password(),signIn.mfa.sendEmailCode(),signIn.mfa.verifyEmailCode()).signIn.create,attemptFirstFactor,setActive) which were causing TypeScript build failures.ClerkErrorobjects without relying on deprecated array structures.API Event Stream Parser:
event:anddata:prefixes).Accept: text/event-streamheader for better proxy/CDN compatibility.