Skip to content

Commit

Permalink
chore: prevent unwanted useEffect trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
ccatherinetan committed May 8, 2024
1 parent 83f7cfc commit dbd215f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ export default function Login() {
const [errorMessage, setErrorMessage] = useState('');
const [emailError, setEmailError] = useState('');
const [passwordError, setPasswordError] = useState('');
const [finishLogin, setFinishLogin] = useState(false);
const { push } = useRouter();
const validEmail = (e: string) => e !== '' && isEmail(e);

useEffect(() => {
if (!auth) throw new Error('Auth must be defined');
if (auth.userId) push(CONFIG.settings);
if (auth.userId && !finishLogin) push(CONFIG.settings);
}, [auth, profile, push]);

const handleSignIn = async () => {
Expand All @@ -50,6 +51,8 @@ export default function Login() {
} else {
profile?.loadProfile();
setErrorMessage('');
setFinishLogin(true);

// conditional routing after logging in
if (profile?.profileReady) {
if (!profile?.profileData) push(CONFIG.onboardingHome);
Expand Down

0 comments on commit dbd215f

Please sign in to comment.