Skip to content

Commit

Permalink
refactor: use generics as the type for the custom ssrApi
Browse files Browse the repository at this point in the history
  • Loading branch information
Sky-FE committed Jun 26, 2024
1 parent eb83a08 commit ed99fa1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/nestjs-backend/src/types/cls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface IClsStore extends ClsStore {
permissions: PermissionAction[];
// for share db adapter
cookie?: string;
setting: {
setting?: {
disallowSignUp: boolean;
disallowSpaceCreation: boolean;
};
Expand Down
14 changes: 6 additions & 8 deletions apps/nextjs-app/src/lib/withAuthSSR.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { ParsedUrlQuery } from 'querystring';
import type { IHttpError } from '@teable/core';
import type {
Expand All @@ -13,15 +14,12 @@ export type GetServerSideProps<
P extends { [key: string]: any } = { [key: string]: any },
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData,
> = (
context: GetServerSidePropsContext<Q, D>,
ssrApi: SsrApi
) => Promise<GetServerSidePropsResult<P>>;
T extends SsrApi = SsrApi,
> = (context: GetServerSidePropsContext<Q, D>, ssrApi: T) => Promise<GetServerSidePropsResult<P>>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function withAuthSSR<P extends { [key: string]: any }>(
handler: GetServerSideProps<P>,
ssrClass: typeof SsrApi = SsrApi
export default function withAuthSSR<P extends { [key: string]: any }, T extends SsrApi>(
handler: GetServerSideProps<P, ParsedUrlQuery, PreviewData, T>,
ssrClass: new () => T = SsrApi as new () => T
): NextGetServerSideProps {
return async (context: GetServerSidePropsContext) => {
const req = context.req;
Expand Down

0 comments on commit ed99fa1

Please sign in to comment.