This commit is contained in:
Jason Ross
2026-03-22 22:54:16 -05:00
parent d8c9ce497a
commit 377e06017d
5 changed files with 15 additions and 15 deletions
@@ -4,4 +4,4 @@ export default function ChatPage() {
Select a conversation to start chatting
</div>
);
}
}
+2 -2
View File
@@ -57,7 +57,7 @@ export default function LoginPage() {
</div>
</form>
<div className="text-center text-sm">
<span className="text-gray-500">Don't have an account? </span>
<span className="text-gray-500">Don&apos;t have an account? </span>
<Link href="/register" className="font-semibold text-blue-600 hover:text-blue-500">
Sign up
</Link>
@@ -65,4 +65,4 @@ export default function LoginPage() {
</div>
</div>
);
}
}
+1 -1
View File
@@ -69,7 +69,7 @@ export default function RegisterPage() {
</form>
<div className="text-center text-sm">
<span className="text-gray-500">Already have an account? </span>
<Link href="/login" className="font-semibold text-blue-600 hover:text-blue-500">
<Link href="/" className="font-semibold text-blue-600 hover:text-blue-500">
Sign in
</Link>
</div>
+7 -7
View File
@@ -33,7 +33,7 @@ export async function login(prevState: any, formData: FormData) {
path: "/",
maxAge: 60 * 60 * 24 * 7, // 1 week
});
redirect("/");
redirect("/c");
}
const errorData = await res.json().catch(() => ({}));
@@ -67,12 +67,12 @@ export async function login(prevState: any, formData: FormData) {
path: "/",
maxAge: 60 * 60 * 24 * 7, // 1 week
});
redirect("/");
redirect("/c");
}
return { error: "Network error occurred." };
}
redirect("/");
redirect("/c");
}
export async function register(prevState: any, formData: FormData) {
@@ -104,7 +104,7 @@ export async function register(prevState: any, formData: FormData) {
path: "/",
maxAge: 60 * 60 * 24 * 7, // 1 week
});
redirect("/");
redirect("/c");
}
const errorData = await res.json().catch(() => ({}));
@@ -138,16 +138,16 @@ export async function register(prevState: any, formData: FormData) {
path: "/",
maxAge: 60 * 60 * 24 * 7, // 1 week
});
redirect("/");
redirect("/c");
}
return { error: "Network error occurred." };
}
redirect("/");
redirect("/c");
}
export async function logout() {
const cookieStore = await cookies();
cookieStore.delete("auth_token");
redirect("/login");
redirect("/");
}
+4 -4
View File
@@ -5,16 +5,16 @@ export function middleware(request: NextRequest) {
const authToken = request.cookies.get('auth_token')
const { pathname } = request.nextUrl
const isAuthRoute = pathname === '/login' || pathname === '/register'
const isAuthRoute = pathname === '/' || pathname === '/register'
// Redirect unauthenticated users to /login
// Redirect unauthenticated users to /
if (!authToken && !isAuthRoute) {
return NextResponse.redirect(new URL('/login', request.url))
return NextResponse.redirect(new URL('/', request.url))
}
// Redirect authenticated users away from auth routes
if (authToken && isAuthRoute) {
return NextResponse.redirect(new URL('/', request.url))
return NextResponse.redirect(new URL('/c', request.url))
}
return NextResponse.next()