-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add support for invitationCode
#213
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughModified Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/state/KindeProvider.tsx (4)
228-234: URL parsing runs on every render.
new URLSearchParams(window.location.search)executes on every render, even though the refs only initialize once. Consider memoizing this or using a lazy initialization pattern:- // Check for invitation_code synchronously before any hooks/rendering - const params = new URLSearchParams(window.location.search); - const hasInvitationCode = params.has("invitation_code"); - const invitationCodeRef = useRef<string | null>( - hasInvitationCode ? params.get("invitation_code") : null, - ); - const isRedirectingRef = useRef(hasInvitationCode); + // Check for invitation_code synchronously before any hooks/rendering + const invitationCodeRef = useRef<string | null>(null); + const isRedirectingRef = useRef(false); + + // Initialize refs only once + if (invitationCodeRef.current === null && isRedirectingRef.current === false) { + const params = new URLSearchParams(window.location.search); + if (params.has("invitation_code")) { + invitationCodeRef.current = params.get("invitation_code"); + isRedirectingRef.current = true; + } + }Alternatively, use a dedicated initialization ref to track whether parsing has been done.
375-376:loginRefis assigned but never read.
loginRefis assigned at line 436 but never used elsewhere. The useEffect at line 439 directly uses thelogincallback from the dependency array instead ofloginRef.current. Either remove the unused ref or use it for the intended immediate access pattern.If the ref is no longer needed:
const initRef = useRef(false); - const loginRef = useRef<typeof login | null>(null); const redirectInitiatedRef = useRef(false);And remove the assignment at lines 435-436.
439-456: Consider invokingonErrorcallback on invitation redirect failure.The catch block logs the error but doesn't notify the application via the
onErrorcallback. This could leave users on a blank screen (since children aren't rendered during redirect) without understanding what went wrong.}).catch((error) => { console.error("Error processing invitation code:", error); + mergedCallbacks.onError?.( + { + error: "ERR_INVITATION_REDIRECT", + errorDescription: String(error), + }, + {}, + {} as KindeContextProps, + ); isRedirectingRef.current = false; redirectInitiatedRef.current = false; });Also note: the
login &&check on line 443 is always true sinceloginis a stableuseCallbackreference.
788-793: Unused variable declaration before early return.The
paramsvariable declared at line 788 is unused whenisRedirectingRef.currentis true (the early return at line 792). Additionally, it shadows theparamsvariable from line 229. Consider removing this redundant parsing or moving it after the guard clause:const init = useCallback(async () => { if (initRef.current) return; try { - const params = new URLSearchParams(window.location.search); - // Skip initialization if redirecting for invitation (handled in useEffect above) if (isRedirectingRef.current) { return; } + const params = new URLSearchParams(window.location.search); + try { initRef.current = true;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package.jsonis excluded by!**/*.json
📒 Files selected for processing (1)
src/state/KindeProvider.tsx(6 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-05T12:17:11.365Z
Learnt from: DanielRivers
Repo: kinde-oss/kinde-auth-react PR: 173
File: src/state/KindeProvider.tsx:584-585
Timestamp: 2025-09-05T12:17:11.365Z
Learning: In Kinde auth React applications, the callback URL (redirectUri) is always absolute because it's required for hosted auth to work properly.
Applied to files:
src/state/KindeProvider.tsx
🔇 Additional comments (1)
src/state/KindeProvider.tsx (1)
890-893: LGTM!The conditional render suppression correctly prevents rendering children during the invitation redirect flow while respecting the
forceChildrenRenderescape hatch.
Explain your changes
Add support for invitations
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.