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
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions src/frontend/with-page-auth-required.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ export interface WithPageAuthRequiredOptions {
* @ignore
*/
export interface WithPageAuthRequiredProps {
user: UserProfile;
[key: string]: any;
}

export interface UserProps {
user: UserProfile;
}

/**
* ```js
* const MyProtectedPage = withPageAuthRequired(MyPage);
Expand All @@ -70,9 +73,9 @@ export interface WithPageAuthRequiredProps {
* @category Client
*/
export type WithPageAuthRequired = <P extends WithPageAuthRequiredProps>(
Component: ComponentType<P>,
Component: ComponentType<P & UserProps>,
options?: WithPageAuthRequiredOptions
) => React.FC<Omit<P, 'user'>>;
) => React.FC<P>;

/**
* @ignore
Expand Down
7 changes: 4 additions & 3 deletions src/helpers/with-page-auth-required.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Claims, GetSession } from '../session';
import { assertCtx } from '../utils/assert';
import React, { ComponentType } from 'react';
import {
UserProps,
WithPageAuthRequiredOptions as WithPageAuthRequiredCSROptions,
WithPageAuthRequiredProps
} from '../frontend/with-page-auth-required';
Expand Down Expand Up @@ -88,19 +89,19 @@ export type WithPageAuthRequiredOptions<P = any, Q extends ParsedUrlQuery = Pars
* @category Server
*/
export type WithPageAuthRequired = {
<P, Q extends ParsedUrlQuery = ParsedUrlQuery>(opts?: WithPageAuthRequiredOptions<P, Q>): PageRoute<P, Q>;
<P extends WithPageAuthRequiredProps>(
Component: ComponentType<P>,
Component: ComponentType<P & UserProps>,
options?: WithPageAuthRequiredCSROptions
): React.FC<P>;
<P, Q extends ParsedUrlQuery = ParsedUrlQuery>(opts?: WithPageAuthRequiredOptions<P, Q>): PageRoute<P, Q>;
};

/**
* @ignore
*/
export default function withPageAuthRequiredFactory(loginUrl: string, getSession: GetSession): WithPageAuthRequired {
return (
optsOrComponent: WithPageAuthRequiredOptions | ComponentType<WithPageAuthRequiredProps> = {},
optsOrComponent: WithPageAuthRequiredOptions | ComponentType<WithPageAuthRequiredProps & UserProps> = {},
csrOpts?: WithPageAuthRequiredCSROptions
): any => {
if (typeof optsOrComponent === 'function') {
Expand Down