refactor: moving locale definition

This commit is contained in:
2024-02-16 17:02:33 +01:00
parent 8992aa76bd
commit 3240f746d1
3 changed files with 6 additions and 3 deletions

View File

@@ -3,6 +3,8 @@ import {getRequestConfig} from 'next-intl/server';
// Can be imported from a shared config // Can be imported from a shared config
export const locales = ['en', 'hr']; export const locales = ['en', 'hr'];
export const defaultLocale = 'en';
export default getRequestConfig(async ({locale}) => { export default getRequestConfig(async ({locale}) => {
// Validate that the incoming `locale` parameter is valid // Validate that the incoming `locale` parameter is valid

View File

@@ -2,6 +2,7 @@ import NextAuth, { NextAuthConfig } from 'next-auth';
import GoogleProvider from 'next-auth/providers/google'; import GoogleProvider from 'next-auth/providers/google';
import { Session } from 'next-auth'; import { Session } from 'next-auth';
import { AuthenticatedUser } from './types/next-auth'; import { AuthenticatedUser } from './types/next-auth';
import { defaultLocale } from '../i18n';
export const authConfig: NextAuthConfig = { export const authConfig: NextAuthConfig = {
callbacks: { callbacks: {
@@ -46,7 +47,7 @@ export const authConfig: NextAuthConfig = {
strategy: 'jwt' strategy: 'jwt'
}, },
pages: { pages: {
signIn: '/en/login', signIn: `/${defaultLocale}/login`,
}, },
}; };

View File

@@ -6,14 +6,14 @@
import { auth, authConfig } from '@/app/lib/auth' import { auth, authConfig } from '@/app/lib/auth'
import createIntlMiddleware from 'next-intl/middleware'; import createIntlMiddleware from 'next-intl/middleware';
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { locales } from '@/app/i18n'; import { locales, defaultLocale } from '@/app/i18n';
const publicPages = ['/terms', '/policy', '/login']; const publicPages = ['/terms', '/policy', '/login'];
const intlMiddleware = createIntlMiddleware({ const intlMiddleware = createIntlMiddleware({
locales, locales,
localePrefix: 'as-needed', localePrefix: 'as-needed',
defaultLocale: 'hr' defaultLocale
}); });
export default async function middleware(req: NextRequest) { export default async function middleware(req: NextRequest) {