Skip to content

Instantly share code, notes, and snippets.

@gasserkl
Created September 8, 2021 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gasserkl/e7011eafb169dea6a8ceefa1bf361640 to your computer and use it in GitHub Desktop.
Save gasserkl/e7011eafb169dea6a8ceefa1bf361640 to your computer and use it in GitHub Desktop.
export function useLogin() {
const [loggedInUsername, setLoggedInUsername] = useState<string | undefined>(
""
);
const [isLoginError, setIsLoginError] = useState(false);
const onLogin = useCallback((username: string, password: string) => {
setIsLoginError(false);
setLoggedInUsername("");
loginUser(username, password).then(({ loginSucceeded, username }) => {
setLoggedInUsername(username);
setIsLoginError(!loginSucceeded);
});
}, []);
return {
loggedInUsername,
isLoginError,
onLogin,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment