Skip to content

Commit

Permalink
feat(nextjs): Enforce withServerSideAuth callback return type
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed Feb 28, 2022
1 parent fd5185c commit 3766a49
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions packages/nextjs/src/middleware/withServerSideAuth.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
import { GetServerSidePropsContext } from 'next';
import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';

import {
WithServerSideAuthCallback,
WithServerSideAuthOptions,
WithServerSideAuthResult,
} from './types';
import {
getAuthData,
injectAuthIntoContext,
injectSSRStateIntoProps,
sanitizeAuthData,
} from './utils';
import { WithServerSideAuthCallback, WithServerSideAuthOptions, WithServerSideAuthResult } from './types';
import { getAuthData, injectAuthIntoContext, injectSSRStateIntoProps, sanitizeAuthData } from './utils';

const EMPTY_GSSP_RESPONSE = { props: {} };

export function withServerSideAuth<
CallbackReturn,
CallbackReturn extends GetServerSidePropsResult<any>,
Options extends WithServerSideAuthOptions,
>(
callback: WithServerSideAuthCallback<CallbackReturn, Options>,
opts?: Options,
): WithServerSideAuthResult<CallbackReturn>;
export function withServerSideAuth(
opts?: WithServerSideAuthOptions,
): WithServerSideAuthResult<void>;
export function withServerSideAuth(opts?: WithServerSideAuthOptions): WithServerSideAuthResult<void>;
export function withServerSideAuth(cbOrOptions: any, options?: any): any {
const cb = typeof cbOrOptions === 'function' ? cbOrOptions : undefined;
const opts = options
? options
: typeof cbOrOptions !== 'function'
? cbOrOptions
: {};
const opts = options ? options : typeof cbOrOptions !== 'function' ? cbOrOptions : {};

return async (ctx: GetServerSidePropsContext) => {
const authData = await getAuthData(ctx, opts);
Expand Down

0 comments on commit 3766a49

Please sign in to comment.