Skip to content

Commit

Permalink
Merge pull request sinamics#498 from sinamics/middleware
Browse files Browse the repository at this point in the history
Replace custom locale middleware with nextjs i18n redirects
  • Loading branch information
sinamics authored Aug 19, 2024
2 parents 71ab890 + 0b7051f commit 13bccd6
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 105 deletions.
14 changes: 12 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ const config = {
* @see https://github.com/vercel/next.js/issues/41980
*/
i18n: {
defaultLocale: "default",
locales: ["default", "en", "fr", "no", "pl", "zh-tw", "zh", "es"],
defaultLocale: "en",
// localeDetection: false,
locales: ["en", "fr", "no", "pl", "zh-tw", "zh", "es"],
},
trailingSlash: true,
eslint: {
ignoreDuringBuilds: true,
},
async redirects() {
return [
{
source: "/",
destination: "/auth/login",
permanent: true,
},
];
},
};
export default config;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import { api } from "~/utils/api";
import { toast } from "react-hot-toast";
import cn from "classnames";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import {
useTrpcApiErrorHandler,
useTrpcApiSuccessHandler,
Expand Down
2 changes: 1 addition & 1 deletion src/components/adminPage/mail/mailNotificationTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
import { api } from "~/utils/api";
import { toast } from "react-hot-toast";
import cn from "classnames";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import {
useTrpcApiErrorHandler,
useTrpcApiSuccessHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
import { api } from "~/utils/api";
import { toast } from "react-hot-toast";
import cn from "classnames";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import {
useTrpcApiErrorHandler,
useTrpcApiSuccessHandler,
Expand Down
2 changes: 1 addition & 1 deletion src/components/adminPage/mail/mailUserInviteTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import { api } from "~/utils/api";
import { toast } from "react-hot-toast";
import cn from "classnames";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import {
useTrpcApiErrorHandler,
useTrpcApiSuccessHandler,
Expand Down
2 changes: 1 addition & 1 deletion src/components/networkByIdPage/networkMtu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRouter } from "next/router";
import { useState, useEffect } from "react";
import { api } from "~/utils/api";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import {
useTrpcApiErrorHandler,
useTrpcApiSuccessHandler,
Expand Down
2 changes: 1 addition & 1 deletion src/components/networkByIdPage/networkMulticast.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRouter } from "next/router";
import { useState, useEffect } from "react";
import { api } from "~/utils/api";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import {
useTrpcApiErrorHandler,
useTrpcApiSuccessHandler,
Expand Down
61 changes: 0 additions & 61 deletions src/middleware.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/admin/mail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type GlobalOptions } from "@prisma/client";
import MailUserInviteTemplate from "~/components/adminPage/mail/mailUserInviteTemplate";
import ForgotPasswordMailTemplate from "~/components/adminPage/mail/mailForgotPasswordTemplate";
import NotificationTemplate from "~/components/adminPage/mail/mailNotificationTemplate";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import OrganizationInviteTemplate from "~/components/adminPage/mail/mailOrganizationInviteTemplate";
import {
useTrpcApiErrorHandler,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/auth/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { api } from "~/utils/api";
import { useRouter } from "next/router";
import classNames from "classnames";
import { ErrorCode, getErrorMessage } from "~/utils/errorCode";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";

const Login = ({ title, oauthExclusiveLogin, oauthEnabled }) => {
const t = useTranslations();
Expand Down
32 changes: 32 additions & 0 deletions src/pages/auth/mfaRecovery/reset/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from "react";
import { useRouter } from "next/router";
import { api } from "~/utils/api";
import { Session } from "next-auth";
import { toast } from "react-hot-toast";
import { type ErrorData, type ZodErrorFieldErrors } from "~/types/errorHandling";
import Head from "next/head";
Expand All @@ -9,6 +10,8 @@ import FormInput from "~/components/auth/formInput";
import FormSubmitButtons from "~/components/auth/formSubmitButton";
import { ErrorCode } from "~/utils/errorCode";
import { useTranslations } from "next-intl";
import { GetServerSideProps, GetServerSidePropsContext } from "next";
import { getSession } from "next-auth/react";

const MfaRecoveryReset = () => {
const t = useTranslations();
Expand Down Expand Up @@ -181,4 +184,33 @@ const MfaRecoveryReset = () => {
);
};

interface Props {
auth?: Session["user"];
}
export const getServerSideProps: GetServerSideProps<Props> = async (
context: GetServerSidePropsContext,
) => {
const session = await getSession(context);
if (!session || !("user" in session) || !session.user) {
return {
props: {
messages: (await import(`~/locales/${context.locale}/common.json`)).default,
},
};
}

if (session.user) {
return {
redirect: {
destination: "/network",
permanent: false,
},
};
}

return {
props: { auth: session.user },
};
};

export default MfaRecoveryReset;
31 changes: 0 additions & 31 deletions src/pages/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/organization/[orgid]/admin/network/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ReactElement } from "react";
import { LayoutOrganizationAuthenticated } from "~/components/layouts/layout";
import { api } from "~/utils/api";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import { useRouter } from "next/router";
import MenuSectionDividerWrapper from "~/components/shared/menuSectionDividerWrapper";

Expand Down
2 changes: 1 addition & 1 deletion src/pages/user-settings/network/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ReactElement } from "react";
import { LayoutAuthenticated } from "~/components/layouts/layout";
import { api } from "~/utils/api";
import { useTranslations } from "use-intl";
import { useTranslations } from "next-intl";
import { User, UserOptions } from "@prisma/client";
import MenuSectionDividerWrapper from "~/components/shared/menuSectionDividerWrapper";

Expand Down

0 comments on commit 13bccd6

Please sign in to comment.