Skip to content
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

Export UserProps for use in higher-order components #1758

Open
5 tasks done
jamesarosen opened this issue Jun 25, 2024 · 0 comments
Open
5 tasks done

Export UserProps for use in higher-order components #1758

jamesarosen opened this issue Jun 25, 2024 · 0 comments

Comments

@jamesarosen
Copy link

jamesarosen commented Jun 25, 2024

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

It would be nice to have UserProps exported so application developers can use it in their own code. For example,

export const withAdmin = <T extends UserProps = UserProps>(
  page: ComponentType<T>
) => {
  const PageWithAdminRequired = (props: T) => {
    const { user } = useUser()
    const router = useRouter()

    if (!isAdmin(user)) {
      router.push('/')
      return null
    }

    return <Page {...props} />
  }

  PageWithAdminRequired.displayName = `${Page.displayName}WithAdminRequired`

  return Page
}

Describe the ideal solution

#574 extracted the UserProps type. It would be nice to have that available in client code.

Alternatives and current workarounds

For now, I have this in my code:

/**
 * @auth0/nextjs-auth doesn't export this, so we copy the definition.
 * @see @auth0/nextjs-auth0/client/with-page-auth-required
 */
export type UserProps = { user: UserProfile };

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant