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

Improve types in server-side withPageAuthRequired #554

Merged

Conversation

misoton665
Copy link
Contributor

@misoton665 misoton665 commented Dec 8, 2021

By submitting a PR to this repository, you agree to the terms within the Auth0 Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

This PR is about server-side withPageAuthRequired.
Because withPageAuthRequired does not accept Query as a type parameter, it's returned GetServerSideProps with a default Query type of ParsedUrlQuery.

withPageAuthRequired({
  getServerSideProps,
  returnTo: "/foo/bar"
});

The type of this will be GetServerSideProps<P, ParsedUrlQuery> no matter what type of getServerSideProps is passed.

In this PR, withPageAuthRequired has been changed so that Query can also be specified as a type parameter.

Testing

Since this is a modification of the type definition, no tests have been added.

  • 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

@misoton665 misoton665 requested a review from a team as a code owner December 8, 2021 12:47
@vercel
Copy link

vercel bot commented Dec 8, 2021

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

A member of the Team first needs to authorize it.

@misoton665
Copy link
Contributor Author

What is the status of this PR?
I believe it is reviewing, but if there is anything I need to do before that, please let me know.

@adamjmcgrath
Copy link
Contributor

Hi @misoton665 - thanks for raising this, apologies for the delay, I haven't got round to looking at this yet. I will do shortly

@adamjmcgrath
Copy link
Contributor

Hi @misoton665

If I add a single type parameter to the server side version of withPageAuthRequired then I get a TS error, because it wants me to use the client side version of the overload

image

I think you need to add a default type argument of ParsedUrlQuery to

<P, Q extends ParsedUrlQuery>(opts?: WithPageAuthRequiredOptions<P, Q>): PageRoute<P, Q>;

@misoton665
Copy link
Contributor Author

misoton665 commented Dec 28, 2021

@adamjmcgrath
Thank you for confirming this.
I've added a commit to give default parameters.
7315459

@adamjmcgrath adamjmcgrath merged commit 2354b49 into auth0:main Jan 4, 2022
@adamjmcgrath
Copy link
Contributor

Thanks @misoton665

@adamjmcgrath adamjmcgrath mentioned this pull request Jan 6, 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.

None yet

2 participants