-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
Description
Problem
KnockProvider always tries to authenticate when mounted, even with undefined userId/userToken. This forces us to wrap it with conditional rendering to avoid auth errors:
function KnockWrapper({ children, userId, userToken }) {
if (!userId || !userToken) {
return children;
}
return <KnockProvider user={{ id: userId }} userToken={userToken}>{children}</KnockProvider>;
}Proposed Solution
Add an enabled prop (similar to KnockGuideProvider's readyToTarget):
<KnockProvider
enabled={Boolean(userId && userToken)}
user={{ id: userId }}
userToken={userToken}
>
{children}
</KnockProvider>When enabled={false}, skip authentication and just render children.
Why?
- Removes boilerplate wrapper components
- Prevents auth errors in unauthenticated states
- Common pattern in React Query, Apollo, etc.
- Especially useful for apps with mixed auth/unauth routes
jsakastherockstorm