fix(frontend): run initial props for children components after getting the user
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -19,8 +19,12 @@ MoviePage.getInitialProps = async (ctx) => {
|
||||
const response = await axios.get<MovieDetailsType>(
|
||||
`http://localhost:${process.env.PORT || 3000}/api/v1/movie/${
|
||||
ctx.query.movieId
|
||||
}?language=${cookies.locale}`,
|
||||
{ headers: ctx.req ? { cookie: ctx.req.headers.cookie } : undefined }
|
||||
}${cookies.locale ? `?language=${cookies.locale}` : ''}`,
|
||||
{
|
||||
headers: ctx.req?.headers?.cookie
|
||||
? { cookie: ctx.req.headers.cookie }
|
||||
: undefined,
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user