Skip to content

Commit

Permalink
adding requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul-py committed Dec 20, 2024
1 parent 3def82a commit dee1a26
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/routes/_unauthenticated/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Route = createFileRoute("/_unauthenticated/signin")({
});

const SignIn = () => {
const { signIn } = useAuthActions();
const { signIn} = useAuthActions();
const [flow, setFlow] = useState<Key>("signIn");
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
Expand All @@ -40,17 +40,17 @@ const SignIn = () => {
const isClosed = process.env.NODE_ENV === "production";

const checkUserExists = async (email: string): Promise<boolean> => {
const response = await fetch('/api/check-user-exists', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
});
try {
const response = await convex.query('checkUserExists', { email });

if (!response.ok) {
return response.exists;
} catch (err) {
if (err instanceof ConvexError && err.message === 'User does not exist') {
return false;
}
console.error(err);
return false;
}
const data = await response.json();
return data.exists;
};

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -77,28 +77,27 @@ const SignIn = () => {
cursor: "pointer",
}}
>
Register a new account?
register a new account
</button>
?
</>
);
setIsSubmitting(false);
return;
}
}

await signIn("password", {
flow,
email,
password,
redirectTo: "/quests",
})
await signIn("password", {
flow,
email,
password,
redirectTo: "/quests",
});
navigate({ to: "/" });
} catch (error) {
setError(
error instanceof Error ? error.message : "An unexpected error occurred."
);
} finally {
} catch (err) {
setError('An unexpected error occurred. Please try again.');
setIsSubmitting(false);
console.error(err);
}
};

Expand Down

0 comments on commit dee1a26

Please sign in to comment.