Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger committed Dec 19, 2024
2 parents df40788 + 65f718f commit 11d945b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vite/HomeBox/LoginOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const getRandomUsername = () => {
return usernames[Math.floor(Math.random() * usernames.length)];
};

const removeWhitespace = (str: string) => str.replace(/\s/g, "");

export const LoginOptions: React.FC<Props> = ({
userNotFound,
setUserNotFound,
Expand All @@ -30,14 +32,15 @@ export const LoginOptions: React.FC<Props> = ({
const handleClick: React.FormEventHandler<HTMLFormElement> = useCallback(
(e) => {
e.preventDefault();
fetch(`https://api.github.com/users/${username}`)
const cleanedUsername = removeWhitespace(username);
fetch(`https://api.github.com/users/${cleanedUsername}`)
.then((response) => response.json())
.then((result) => {
if (result.message === "Not Found") {
setUserNotFound(true);
} else {
setUserNotFound(false);
window.location.href = `/loading/${username}`;
window.location.href = `/loading/${cleanedUsername}`;
}
})
.catch((error) => console.log("error", error));
Expand Down

0 comments on commit 11d945b

Please sign in to comment.