finished reset password & other changes

This commit is contained in:
2024-04-24 22:37:55 +03:00
parent b1ad7b5c3e
commit 53cadc289a
58 changed files with 1520 additions and 349 deletions

View File

@@ -1,17 +1,11 @@
import { NextURL } from 'next/dist/server/web/next-url'
import NextAuth from 'next-auth'
import { createI18nMiddleware } from 'next-international/middleware'
import { NextRequest, NextResponse } from 'next/server'
import { defaultLocale, locales } from '@/config/locales'
import authConfig from '@/auth.config'
import {
apiAuthPrefix,
AUTH_LOGIN_URL,
authRoutes,
DEFAULT_LOGIN_REDIRECT,
publicRoutes,
testPathnameRegex,
} from '@/config/routes'
import { NextURL } from 'next/dist/server/web/next-url'
import { apiAuthPrefix, AUTH_LOGIN_URL, authRoutesRegEx, DEFAULT_LOGIN_REDIRECT, publicRoutes } from '@/config/routes'
import { testPathnameRegex } from '@/lib/utils'
import { createI18nMiddleware } from 'next-international/middleware'
interface AppRouteHandlerFnContext {
params?: Record<string, string | string[]>;
@@ -19,11 +13,12 @@ interface AppRouteHandlerFnContext {
export const middleware = (request: NextRequest, event: AppRouteHandlerFnContext): NextResponse | null => {
return NextAuth(authConfig).auth((request): any => {
const { nextUrl }: { nextUrl: NextURL } = request
const isLoggedIn: boolean = !!request.auth
const isApiAuthRoute: boolean = nextUrl.pathname.startsWith(apiAuthPrefix)
const isPublicRoute: boolean = testPathnameRegex(publicRoutes, nextUrl.pathname)
const isAuthRoute: boolean = testPathnameRegex(authRoutes, nextUrl.pathname)
const isAuthRoute: boolean = testPathnameRegex(authRoutesRegEx, nextUrl.pathname)
if (isApiAuthRoute) {
return null
@@ -49,8 +44,23 @@ export const middleware = (request: NextRequest, event: AppRouteHandlerFnContext
})(request, event) as NextResponse
}
// export const config = {
// matcher: [
// /*
// * Match all request paths except for the ones starting with:
// * - api (API routes)
// * - _next/static (static files)
// * - _next/image (image optimization files)
// * - favicon.ico (favicon file)
// */
// {
// source: '/((?!.+\\.[\\w]+$|api|_next/image|favicon.ico|robots.txt|trpc).*)', missing: [
// { type: 'header', key: 'next-router-prefetch' }, { type: 'header', key: 'purpose', value: 'prefetch' }],
// }],
// }
export const config = {
matcher: [
'/((?!.+\\.[\\w]+$|_next).*)', '/(api|static|trpc)(.*)'],
}
'/((?!.+\\.[\\w]+$|_next|_next/image|_next/static).*)', '/(api|trpc)(.*)',
],
}