Skip to content

Commit

Permalink
Improve types in server-side withPageAuthRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
misoton665 committed Dec 8, 2021
1 parent c5d4fff commit 47d306b
Showing 1 changed file with 7 additions and 4 deletions.
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>(opts?: WithPageAuthRequiredOptions<P, Q>): PageRoute<P, Q>;
<P extends WithPageAuthRequiredProps>(
Component: ComponentType<P>,
options?: WithPageAuthRequiredCSROptions
Expand Down

0 comments on commit 47d306b

Please sign in to comment.