next#GetServerSidePropsResult TypeScript Examples

The following examples show how to use next#GetServerSidePropsResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: locales.ts    From compose-starter-helpcenter-nextjs with MIT License 6 votes vote down vote up
withLocale = (
  fn: (
    locale: Locale,
    context: GetServerSidePropsContext
  ) => Promise<GetServerSidePropsResult<Record<string, unknown>>>
) => {
  return (context: GetServerSidePropsContext) => {
    const locale = getLocale(context.params.locale);

    switch (locale) {
      case UnknownLocale:
        context.res.writeHead(302, { Location: '/' }).end();
        break;
      case undefined:
        context.res.statusCode = 404;
        break;
      default:
        return fn(locale, context);
    }
  };
}
Example #2
Source File: index.ts    From po8klasie with GNU General Public License v3.0 6 votes vote down vote up
getServerSideProps = async (
  context: GetServerSidePropsContext<ProjectIndexPageParams>,
): Promise<GetServerSidePropsResult<{ PROJECT: Partial<ProjectConfig> }>> => {
  const projectID = context?.params?.projectID;

  if (!projectID) {
    return {
      notFound: true,
    };
  }

  return {
    redirect: {
      destination: `/${projectID}/search`,
      permanent: false,
    },
  };
}
Example #3
Source File: [schoolID].tsx    From po8klasie with GNU General Public License v3.0 6 votes vote down vote up
getServerSideProps = async (
  context: GetServerSidePropsContext<SchoolPageParams>,
): Promise<
  GetServerSidePropsResult<{ PROJECT: Partial<ProjectConfig>; school: RailsApiSchool }>
> => {
  const schoolID = context?.params?.schoolID;
  const projectID = context?.params?.projectID;

  if (!schoolID || !projectID)
    return {
      notFound: true,
    };

  const fetcher = await import('../../../api/railsAPI/fetcher').then((m) => m.default);
  const school = (await fetcher(`/institutions/${schoolID}`)) as RailsApiSchool;

  if (!school.id) return { notFound: true };

  return {
    props: {
      PROJECT: await getProjectConfigProps(['appearance', 'schoolInfo'], projectID),
      school,
    },
  };
}
Example #4
Source File: search.tsx    From po8klasie with GNU General Public License v3.0 6 votes vote down vote up
getServerSideProps = async (
  context: GetServerSidePropsContext<SearchPageParams>,
): Promise<GetServerSidePropsResult<{ PROJECT: Partial<ProjectConfig> }>> => {
  const projectID = context?.params?.projectID;

  if (!projectID)
    return {
      notFound: true,
    };

  return {
    props: {
      PROJECT: await getProjectConfigProps(['appearance', 'searchView'], projectID),
    },
  };
}
Example #5
Source File: index.tsx    From po8klasie with GNU General Public License v3.0 6 votes vote down vote up
getServerSideProps = async ({
  locale,
}: GetServerSidePropsContext): Promise<GetServerSidePropsResult<any>> => ({
  props: {
    ...(await serverSideTranslations(locale as string, ['landing'])),
    projectsList: Object.values(projectConfigs).map(({ projectID, appearance }) => ({
      projectID,
      appName: appearance.appName,
    })),
  },
})
Example #6
Source File: securedProps.ts    From frontend with MIT License 6 votes vote down vote up
securedProps: (
  ctx: GetServerSidePropsContext,
  returnUrl?: string,
) => Promise<GetServerSidePropsResult<Session>> = async (ctx, returnUrl?: string) => {
  const session = await getSession(ctx)
  let url = returnUrl ?? ctx.req.url ?? ''
  if (url.startsWith('/_next') || url.startsWith('/_error')) url = '/'
  if (!session) {
    return {
      redirect: {
        destination: `${routes.login}?callbackUrl=${encodeURIComponent(url)}`,
        permanent: false,
      },
    }
  }

  return {
    props: session,
  }
}
Example #7
Source File: testingUtils.tsx    From crosshare with GNU Affero General Public License v3.0 5 votes vote down vote up
export async function getProps<T>(a: GetServerSidePropsResult<T>) {
  if (!hasOwnProperty(a, 'props')) {
    throw new Error('should have props');
  }
  return await Promise.resolve(a.props);
}