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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/helpers/with-page-auth-required.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
WithPageAuthRequiredProps
} from '../frontend/with-page-auth-required';
import { withPageAuthRequired as withPageAuthRequiredCSR } from '../frontend';
import { ParsedUrlQuery } from 'querystring';

/**
* If you wrap your `getServerSideProps` with {@link WithPageAuthRequired} your props object will be augmented with
Expand All @@ -32,7 +33,9 @@ export type GetServerSidePropsResultWithSession<P = any> = GetServerSidePropsRes
*
* @category Server
*/
export type PageRoute<P> = (cts: GetServerSidePropsContext) => Promise<GetServerSidePropsResultWithSession<P>>;
export type PageRoute<P, Q extends ParsedUrlQuery> = (
cts: GetServerSidePropsContext<Q>
) => Promise<GetServerSidePropsResultWithSession<P>>;

/**
* If you have a custom returnTo url you should specify it in `returnTo`.
Expand Down Expand Up @@ -60,8 +63,8 @@ export type PageRoute<P> = (cts: GetServerSidePropsContext) => Promise<GetServer
*
* @category Server
*/
export type WithPageAuthRequiredOptions<P = any> = {
getServerSideProps?: GetServerSideProps<P>;
export type WithPageAuthRequiredOptions<P = any, Q extends ParsedUrlQuery = ParsedUrlQuery> = {
getServerSideProps?: GetServerSideProps<P, Q>;
returnTo?: string;
};

Expand All @@ -85,7 +88,7 @@ export type WithPageAuthRequiredOptions<P = any> = {
* @category Server
*/
export type WithPageAuthRequired = {
<P>(opts?: WithPageAuthRequiredOptions<P>): PageRoute<P>;
<P, Q extends ParsedUrlQuery = ParsedUrlQuery>(opts?: WithPageAuthRequiredOptions<P, Q>): PageRoute<P, Q>;
<P extends WithPageAuthRequiredProps>(
Component: ComponentType<P>,
options?: WithPageAuthRequiredCSROptions
Expand Down