Source: pages/publish/index.js

  1. /** @module pages/publish */
  2. import { getAuthProps } from "../../lib/auth";
  3. import CreateOrEdit from "../../containers/create-or-edit";
  4. import Head from "next/head";
  5. import { getUserAgentProps } from "../../lib/user-agent";
  6. import { serverSideTranslations } from "next-i18next/serverSideTranslations";
  7. import { useTranslation } from "next-i18next";
  8. export default function Home(props) {
  9. const { t } = useTranslation("editor");
  10. return (
  11. <>
  12. <Head>
  13. <title>{t("create-dream")}</title>
  14. </Head>
  15. <CreateOrEdit {...props} />
  16. </>
  17. );
  18. }
  19. export async function getServerSideProps(context) {
  20. const authProps = await getAuthProps(context);
  21. if (!authProps.props.serverSession) {
  22. const { res } = context;
  23. res.setHeader("location", `/${context.locale}/auth/signin`);
  24. res.statusCode = 302;
  25. res.end();
  26. }
  27. return {
  28. props: {
  29. ...authProps.props,
  30. ...getUserAgentProps(context),
  31. ...(await serverSideTranslations(context.locale, [
  32. "dashboard",
  33. "editor",
  34. "common",
  35. ])),
  36. },
  37. };
  38. }