refactor: moving locale definition
This commit is contained in:
@@ -4,6 +4,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
|
||||||
if (!locales.includes(locale as any)) notFound();
|
if (!locales.includes(locale as any)) notFound();
|
||||||
|
|||||||
@@ -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`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user