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 server-side withPageAuthRequired #512

Merged
merged 2 commits into from
Oct 7, 2021
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
14 changes: 7 additions & 7 deletions src/helpers/with-page-auth-required.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ import { withPageAuthRequired as withPageAuthRequiredCSR } from '../frontend';
*
* @category Server
*/
export type GetServerSidePropsResultWithSession = GetServerSidePropsResult<{
user?: Claims | null;
[key: string]: any;
}>;
export type GetServerSidePropsResultWithSession<P = any> = GetServerSidePropsResult<P & { user?: Claims | null }>;

/**
* A page route that has been augmented with {@link WithPageAuthRequired}
*
* @category Server
*/
export type PageRoute = (cts: GetServerSidePropsContext) => Promise<GetServerSidePropsResultWithSession>;
export type PageRoute<P> = (cts: GetServerSidePropsContext) => Promise<GetServerSidePropsResultWithSession<P>>;

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

/**
* Wrap your `getServerSideProps` with this method to make sure the user is authenticated before visiting the page.
Expand All @@ -85,7 +85,7 @@ export type WithPageAuthRequiredOptions = { getServerSideProps?: GetServerSidePr
* @category Server
*/
export type WithPageAuthRequired = {
(opts?: WithPageAuthRequiredOptions): PageRoute;
<P>(opts?: WithPageAuthRequiredOptions<P>): PageRoute<P>;
<P extends WithPageAuthRequiredProps>(
Component: ComponentType<P>,
options?: WithPageAuthRequiredCSROptions
Expand Down