Skip to content

Commit 6eae7d8

Browse files
committed
feat: implement authentication check and streamline proxy function
- Added checkAuth function to validate user session and redirect to sign-in if not authenticated. - Updated proxy function to remove session cookie handling and simplify redirection logic. - Modified MePage component to include authentication check before rendering profile data.
1 parent ce13f59 commit 6eae7d8

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

app/(landing)/me/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ProfileData } from './profile-data';
2+
import { checkAuth } from '@/lib/check-auth';
23

34
export default async function MePage() {
5+
await checkAuth();
46
return (
57
<section className=''>
68
<ProfileData />

lib/check-auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { authClient } from './auth-client';
2+
import { redirect } from 'next/navigation';
3+
4+
export const checkAuth = async () => {
5+
const session = await authClient.getSession();
6+
if (!session) {
7+
redirect('/auth?mode=signin');
8+
}
9+
return session;
10+
};

proxy.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import { getSessionCookie } from 'better-auth/cookies';
2-
import type { NextRequest } from 'next/server';
31
import { NextResponse } from 'next/server';
42

5-
export async function proxy(request: NextRequest) {
6-
const cookies = getSessionCookie(request);
7-
if (!cookies) {
8-
return NextResponse.redirect(new URL('/register', request.url));
9-
}
3+
export async function proxy() {
104
return NextResponse.next();
115
}
126

137
export const config = {
14-
matcher: [''],
8+
matcher: ['/'],
159
};

0 commit comments

Comments
 (0)