Skip to content

Commit b080eb8

Browse files
committed
feat: add sitemap, robots.txt, and authentication middleware for SEO and routing control
1 parent 0b39aa3 commit b080eb8

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/app/robots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function robots(): MetadataRoute.Robots {
55
rules: {
66
userAgent: '*',
77
allow: '/',
8-
disallow: ['/dashboard', '/api/', '/_next/', '/private/'],
8+
disallow: ['/dashboard', '/api/', '/_next/', '/private/', '/sign-in', '/sign-up', '/verify'],
99
},
1010
sitemap: 'https://www.whispers-within.in/sitemap.xml',
1111
}

src/app/sitemap.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,8 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
6767
changeFrequency: 'monthly',
6868
priority: 0.7,
6969
},
70-
{
71-
url: `${baseUrl}/confessions`,
72-
lastModified: new Date(),
73-
changeFrequency: 'daily',
74-
priority: 0.8,
75-
},
70+
// NOTE: /confessions is excluded from sitemap because its layout sets
71+
// robots: { index: false }. Including it here would send conflicting signals.
7672
{
7773
url: `${baseUrl}/privacy`,
7874
lastModified: new Date(),

src/middleware.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import { getToken } from 'next-auth/jwt';
3-
export { default } from 'next-auth/middleware';
43

54
export const config = {
6-
matcher: ['/dashboard/:path*', '/sign-in', '/sign-up', '/', '/verify/:path*'],
5+
// Only match routes that genuinely need auth checks.
6+
// Public pages (/, /about, /blog, /faq, /contact, /confessions, /privacy, /terms, /u/*)
7+
// must NOT be in this list — Googlebot needs to crawl them without redirects.
8+
matcher: ['/dashboard/:path*', '/sign-in', '/sign-up', '/verify/:path*'],
79
};
810

911
export async function middleware(request: NextRequest) {
1012
const token = await getToken({ req: request });
1113
const url = request.nextUrl;
1214

13-
// Redirect to dashboard if the user is already authenticated
14-
// and trying to access sign-in, sign-up, or home page
15+
// Redirect authenticated users away from auth pages to dashboard
1516
if (
1617
token &&
1718
(url.pathname.startsWith('/sign-in') ||
@@ -21,6 +22,7 @@ export async function middleware(request: NextRequest) {
2122
return NextResponse.redirect(new URL('/dashboard', request.url));
2223
}
2324

25+
// Redirect unauthenticated users away from dashboard to sign-in
2426
if (!token && url.pathname.startsWith('/dashboard')) {
2527
return NextResponse.redirect(new URL('/sign-in', request.url));
2628
}

0 commit comments

Comments
 (0)