Skip to content

Feature request: Add enabled prop to KnockProvider #807

@zubhav

Description

@zubhav

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions