Przeglądaj źródła

Fixed behavior to ensure correct functionality

maeshinshin 1 rok temu
rodzic
commit
b773722958

+ 8 - 8
apps/app/src/pages/user-activation.page.tsx

@@ -1,4 +1,4 @@
-import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
+import type { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
 import { useTranslation } from 'next-i18next';
 import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
 import Head from 'next/head';
@@ -8,10 +8,12 @@ import { NoLoginLayout } from '~/components/Layout/NoLoginLayout';
 import type { CrowiRequest } from '~/interfaces/crowi-request';
 import type { UserActivationErrorCode } from '~/interfaces/errors/user-activation';
 import type { RegistrationMode } from '~/interfaces/registration-mode';
-import { IUserRegistrationOrder } from '~/server/models/user-registration-order';
+import type { IUserRegistrationOrder } from '~/server/models/user-registration-order';
+import type { CrowiReq } from '~/server/routes/user-activation';
 
+import type { CommonProps } from './utils/commons';
 import {
-  getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle, CommonProps,
+  getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle,
 } from './utils/commons';
 
 type Props = CommonProps & {
@@ -56,18 +58,17 @@ async function injectNextI18NextConfigurations(context: GetServerSidePropsContex
 
 export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
   const result = await getServerSideCommonProps(context);
-  const req: CrowiRequest = context.req as CrowiRequest;
+  const req: CrowiReq & CrowiRequest = context.req as CrowiReq & CrowiRequest;
 
   // check for presence
   // see: https://github.com/vercel/next.js/issues/19271#issuecomment-730006862
   if (!('props' in result)) {
     throw new Error('invalid getSSP result');
   }
-
   const props: Props = result.props as Props;
 
-  if (context.query.userRegistrationOrder != null) {
-    const userRegistrationOrder = context.query.userRegistrationOrder as unknown as IUserRegistrationOrder;
+  if (req.userRegistrationOrder != null) {
+    const userRegistrationOrder = req.userRegistrationOrder as unknown as IUserRegistrationOrder;
     props.email = userRegistrationOrder.email;
     props.token = userRegistrationOrder.token;
   }
@@ -75,7 +76,6 @@ export const getServerSideProps: GetServerSideProps = async(context: GetServerSi
   if (typeof context.query.errorCode === 'string') {
     props.errorCode = context.query.errorCode as UserActivationErrorCode;
   }
-
   props.registrationMode = req.crowi.configManager.getConfig('crowi', 'security:registrationMode');
   props.isEmailAuthenticationEnabled = req.crowi.configManager.getConfig('crowi', 'security:passport-local:isEmailAuthenticationEnabled');
 

+ 3 - 3
apps/app/src/server/routes/user-activation.ts

@@ -1,14 +1,14 @@
-import { Response, NextFunction } from 'express';
+import type { Response, NextFunction } from 'express';
 
 import type { UserActivationErrorCode } from '~/interfaces/errors/user-activation';
-import { ReqWithUserRegistrationOrder } from '~/server/middlewares/inject-user-registration-order-by-token-middleware';
+import type { ReqWithUserRegistrationOrder } from '~/server/middlewares/inject-user-registration-order-by-token-middleware';
 
 type Crowi = {
   // eslint-disable-next-line @typescript-eslint/no-explicit-any
   nextApp: any,
 }
 
-type CrowiReq = ReqWithUserRegistrationOrder & {
+export type CrowiReq = ReqWithUserRegistrationOrder & {
   crowi: Crowi,
 }