Restructure application to use /home for authenticated pages
- Move authenticated home page from /[locale] to /[locale]/home - Move login page from /[locale]/login to /[locale] (new landing page) - Move all restricted pages (bill, location, year-month, print, account) under /[locale]/home - Simplify middleware to protect all routes under /home instead of using publicPages array - Update auth config: change signIn page from /login to / - Update SignInButton callback URL to redirect to /home after login - Update all internal links throughout the application to reflect new structure - Update server action redirects in navigationActions.ts - Public share routes (/share/*) remain unchanged 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,9 +9,6 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { locales, defaultLocale } from '@/app/i18n';
|
||||
import { Session } from 'next-auth';
|
||||
|
||||
// http://localhost:3000/share/location/675c41b227d0df76a35f106e
|
||||
const publicPages = ['/terms', '/policy', '/login', '/share/location/.*', '/share/bill/.*', '/share/attachment/.*', '/share/proof-of-payment/.*'];
|
||||
|
||||
const intlMiddleware = createIntlMiddleware({
|
||||
locales,
|
||||
localePrefix: 'as-needed',
|
||||
@@ -19,19 +16,19 @@ const intlMiddleware = createIntlMiddleware({
|
||||
});
|
||||
|
||||
export default async function middleware(req: NextRequest) {
|
||||
const publicPathnameRegex = RegExp(
|
||||
`^(/(${locales.join('|')}))?(${publicPages
|
||||
.flatMap((p) => (p === '/' ? ['', '/'] : p))
|
||||
.join('|')})/?$`,
|
||||
// All routes under /home require authentication
|
||||
// Check if the path (after optional locale prefix) starts with /home
|
||||
const homeRouteRegex = RegExp(
|
||||
`^(/(${locales.join('|')}))?/home(/.*)?$`,
|
||||
'i'
|
||||
);
|
||||
const isPublicPage = publicPathnameRegex.test(req.nextUrl.pathname);
|
||||
const isProtectedPage = homeRouteRegex.test(req.nextUrl.pathname);
|
||||
|
||||
// for public pages we call only localisation middleware
|
||||
// this is not an official way to do it - it's a hack
|
||||
// For protected pages (under /home), verify authentication
|
||||
// This is not an official way to do it - it's a hack
|
||||
// based on https://github.com/nextauthjs/next-auth/discussions/8961
|
||||
// The official way of chaining middlewares in AuthJS v5 does not work and is not fully documented
|
||||
if (!isPublicPage) {
|
||||
if (isProtectedPage) {
|
||||
|
||||
const session = await myAuth();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user