Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import * as React from "react";
  2. import { useAuthState } from "../../helpers/authHelper";
  3. import { Redirect } from "react-router";
  4.  
  5. const SignIn = () => {
  6. const [username, setUsername] = React.useState("");
  7. const [password, setPassword] = React.useState("");
  8. const [isSignedIn, setAuth] = useAuthState();
  9. if (isSignedIn) {
  10. return <Redirect to="/home" />;
  11. }
  12.  
  13. const changeUsername: React.ChangeEventHandler<HTMLInputElement> = e => {
  14. setUsername(e.currentTarget.value);
  15. };
  16. const changePassword: React.ChangeEventHandler<HTMLInputElement> = e => {
  17. setPassword(e.currentTarget.value);
  18. };
  19.  
  20. const handleSubmit = () => {
  21. setAuth({
  22. id: username,
  23. password,
  24. });
  25. };
  26.  
  27. return (
  28. <div>
  29. <div>
  30. <input
  31. placeholder="Username"
  32. type="text"
  33. value={username}
  34. onChange={changeUsername}
  35. />
  36. </div>
  37. <div>
  38. <input
  39. placeholder="Password"
  40. type="password"
  41. value={password}
  42. onChange={changePassword}
  43. />
  44. </div>
  45.  
  46. <input type="button" onClick={handleSubmit} value="Sign In" />
  47. </div>
  48. );
  49. };
  50. export default SignIn;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement