From 3240f746d1408c952839645969da5b90f8b7fc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Fri, 16 Feb 2024 17:02:33 +0100 Subject: [PATCH] refactor: moving locale definition --- app/i18n.ts | 2 ++ app/lib/auth.ts | 3 ++- middleware.ts | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/i18n.ts b/app/i18n.ts index a5eefda..d93ff27 100644 --- a/app/i18n.ts +++ b/app/i18n.ts @@ -3,6 +3,8 @@ import {getRequestConfig} from 'next-intl/server'; // Can be imported from a shared config export const locales = ['en', 'hr']; + +export const defaultLocale = 'en'; export default getRequestConfig(async ({locale}) => { // Validate that the incoming `locale` parameter is valid diff --git a/app/lib/auth.ts b/app/lib/auth.ts index 3662fa7..f7f94b2 100644 --- a/app/lib/auth.ts +++ b/app/lib/auth.ts @@ -2,6 +2,7 @@ import NextAuth, { NextAuthConfig } from 'next-auth'; import GoogleProvider from 'next-auth/providers/google'; import { Session } from 'next-auth'; import { AuthenticatedUser } from './types/next-auth'; +import { defaultLocale } from '../i18n'; export const authConfig: NextAuthConfig = { callbacks: { @@ -46,7 +47,7 @@ export const authConfig: NextAuthConfig = { strategy: 'jwt' }, pages: { - signIn: '/en/login', + signIn: `/${defaultLocale}/login`, }, }; diff --git a/middleware.ts b/middleware.ts index 4fad9e8..b2ab9a4 100644 --- a/middleware.ts +++ b/middleware.ts @@ -6,14 +6,14 @@ import { auth, authConfig } from '@/app/lib/auth' import createIntlMiddleware from 'next-intl/middleware'; import { NextRequest, NextResponse } from 'next/server'; -import { locales } from '@/app/i18n'; +import { locales, defaultLocale } from '@/app/i18n'; const publicPages = ['/terms', '/policy', '/login']; const intlMiddleware = createIntlMiddleware({ locales, localePrefix: 'as-needed', - defaultLocale: 'hr' + defaultLocale }); export default async function middleware(req: NextRequest) {