|
|
@@ -1,4 +1,6 @@
|
|
|
-import { DevidedPagePath, Lang, AllLang } from '@growi/core';
|
|
|
+import {
|
|
|
+ DevidedPagePath, Lang, AllLang, IUser, IUserHasId,
|
|
|
+} from '@growi/core';
|
|
|
import { GetServerSideProps, GetServerSidePropsContext } from 'next';
|
|
|
import { SSRConfig, UserConfig } from 'next-i18next';
|
|
|
|
|
|
@@ -22,13 +24,14 @@ export type CommonProps = {
|
|
|
isMaintenanceMode: boolean,
|
|
|
redirectDestination: string | null,
|
|
|
customizedLogoSrc?: string,
|
|
|
+ currentUser?: IUser,
|
|
|
} & Partial<SSRConfig>;
|
|
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
export const getServerSideCommonProps: GetServerSideProps<CommonProps> = async(context: GetServerSidePropsContext) => {
|
|
|
|
|
|
- const req: CrowiRequest = context.req as CrowiRequest;
|
|
|
- const { crowi } = req;
|
|
|
+ const req = context.req as CrowiRequest<IUserHasId & any>;
|
|
|
+ const { crowi, user } = req;
|
|
|
const {
|
|
|
appService, configManager, customizeService,
|
|
|
} = crowi;
|
|
|
@@ -38,6 +41,11 @@ export const getServerSideCommonProps: GetServerSideProps<CommonProps> = async(c
|
|
|
|
|
|
const isMaintenanceMode = appService.isMaintenanceMode();
|
|
|
|
|
|
+ let currentUser;
|
|
|
+ if (user != null) {
|
|
|
+ currentUser = user.toObject();
|
|
|
+ }
|
|
|
+
|
|
|
// eslint-disable-next-line max-len, no-nested-ternary
|
|
|
const redirectDestination = !isMaintenanceMode && currentPathname === '/maintenance' ? '/' : isMaintenanceMode && !currentPathname.match('/admin/*') && !(currentPathname === '/maintenance') ? '/maintenance' : null;
|
|
|
const isDefaultLogo = crowi.configManager.getConfig('crowi', 'customize:isDefaultLogo');
|
|
|
@@ -56,6 +64,7 @@ export const getServerSideCommonProps: GetServerSideProps<CommonProps> = async(c
|
|
|
isMaintenanceMode,
|
|
|
redirectDestination,
|
|
|
customizedLogoSrc: isDefaultLogo ? null : configManager.getConfig('crowi', 'customize:customizedLogoSrc'),
|
|
|
+ currentUser,
|
|
|
};
|
|
|
|
|
|
return { props };
|