fix(frontend): run initial props for children components after getting the user

This commit is contained in:
sct
2020-09-18 01:03:04 +00:00
parent 9131254f33
commit fdf9f38776
11 changed files with 158 additions and 71 deletions

View File

@@ -85,22 +85,12 @@ const CoreApp: Omit<NextAppComponentType, 'origGetInitialProps'> = ({
};
CoreApp.getInitialProps = async (initialProps) => {
// Run the default getInitialProps for the main nextjs initialProps
const appInitialProps: AppInitialProps = await App.getInitialProps(
initialProps
);
const { ctx, router } = initialProps;
let user = undefined;
let locale = 'en';
if (ctx.res) {
const cookies = parseCookies(ctx);
if (cookies.locale) {
locale = cookies.locale;
}
try {
// Attempt to get the user by running a request to the local api
const response = await axios.get<User>(
@@ -126,8 +116,19 @@ CoreApp.getInitialProps = async (initialProps) => {
ctx.res.end();
}
}
const cookies = parseCookies(ctx);
if (!!cookies.locale) {
locale = cookies.locale;
}
}
// Run the default getInitialProps for the main nextjs initialProps
const appInitialProps: AppInitialProps = await App.getInitialProps(
initialProps
);
const messages = await loadLocaleData(locale);
return { ...appInitialProps, user, messages, locale };