fix: redirect logged-in users from login page to dashboard
When a user with a valid session visits /login, they now get redirected to the dashboard (/) instead of seeing the login form. Uses the existing useLoginQuery hook to verify auth state server-side before rendering. Fixes #4094
This commit is contained in:
1 parent
0a838649b7
commit
0e329170d1
1 file changed
+17
-1
@@ -1,8 +1,24 @@
|
||||
'use client';
|
||||
import { Column } from '@umami/react-zen';
|
||||
import { Column, Loading } from '@umami/react-zen';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
import { useLoginQuery } from '@/components/hooks';
|
||||
import { LoginForm } from './LoginForm';
|
||||
|
||||
export function LoginPage() {
|
||||
const { user, isLoading } = useLoginQuery();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
router.replace('/');
|
||||
}
|
||||
}, [user, router]);
|
||||
|
||||
if (isLoading || user) {
|
||||
return <Loading placement="absolute" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Column alignItems="center" height="100vh" backgroundColor="2" paddingTop="12">
|
||||
<LoginForm />
|
||||
|
||||
Reference in new issue
Block a user