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

Fix types in client-side withPageAuthRequired #574

Merged
merged 3 commits into from
Jan 13, 2022
Merged

Fix types in client-side withPageAuthRequired #574

merged 3 commits into from
Jan 13, 2022

Conversation

slaypni
Copy link
Contributor

@slaypni slaypni commented Jan 11, 2022

Description

This PR modifies types related to client-side withPageAuthRequired to fix several issues.

  • Return type of withPageAuthRequired has user in props incorrectly
  • Passing { user: UserProfile } as a part of generic parameter of withPageAuthRequired seems redundant
  • Props of component passed to withPageAuthRequired does not infer types properly

These issues are commented in a sample code below:

export async function getStaticProps() {
  return {
    props: {
      locale: "en"
    }
  };
}

// passing `{ user: UserProfile }` as a part of generic parameter for `withPageAuthRequired` is necessary, that seems redundant.
const Page = withPageAuthRequired<InferGetStaticPropsType<typeof getStaticProps> & { user: UserProfile }>(
  ({ locale, user }) => {    
    // `locale` and `user` are inferred `any` here. they should be `string` and `UserProfile`.
    return <></>;
  }
);
// type of `Page` is `FC<{ locale: string; } & { user: UserProfile; }>`, where `{ user: UserProfile }` is improper.
export default Page

Solutions

  • Take { user: UserProfile } apart from WithPageAuthRequiredProps
  • Swap call signatures in WithPageAuthRequired for the last issue
    • Although I am not sure the cause of the improper type inference

Testing

If this PR solves those issues can be checked by following code:

export async function getStaticProps() {
  return {
    props: {
      locale: "en"
    }
  };
}

// `{ user: UserProfile }` can be omitted from generic parameter
const Page = withPageAuthRequired<InferGetStaticPropsType<typeof getStaticProps>>(
  // type of `locale` is `string` and `user` is `UserProfile`
  ({ locale, user }) => {    
    return <></>;
  }
);
// type of `Page` is `FC<{ locale: string; }>`
export default Page

TypeScript 4.5.4 is used for my check

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not main

@slaypni slaypni requested a review from a team as a code owner January 11, 2022 14:17
@vercel
Copy link

vercel bot commented Jan 11, 2022

@slaypni is attempting to deploy a commit to the Auth0 Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@adamjmcgrath adamjmcgrath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - thanks @slaypni

@adamjmcgrath adamjmcgrath merged commit 5b6007f into auth0:main Jan 13, 2022
@slaypni slaypni deleted the fix-type-page-auth-csr branch January 14, 2022 14:48
@adamjmcgrath adamjmcgrath mentioned this pull request May 4, 2022
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

Successfully merging this pull request may close these issues.

2 participants