Rank 2: Process
As the title says. I want to log my users in but sometimes they get an error. For instance password too short or maybe credentials dont match.
Is there a way i can catch the error type and turn that into a variable i can use.
const IsLoggedIn = async () => { try { var res = await account.get(); if (res) { redirectTo("./homepage"); } } catch (e) { setLoading(false); } };
async function handleLogin() { try { setLoading(true); await account.createEmailSession(email, password); setPassword(""); setLoading(false); IsLoggedIn(); } catch (error) { console.error(error); setLoading(false); } }
async function handleRegister() { try { setLoading(true); await account.create(ID.unique(), email, password); setPassword(""); setLoading(false); IsLoggedIn(); } catch (error) { console.error(error);
setLoading(false); } }
const redirectTo = (path) => { router.replace(path); };
useEffect(() => { IsLoggedIn(); }, []);