fixing auth, added registration page
parent
4ea0a209f5
commit
3a785c212a
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<title>Zgłaszańsko</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="./register.tsx"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,78 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import React, { ReactElement, useEffect, useState } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import Nav from "./Nav";
|
||||
import "./styles/reset.css";
|
||||
import "./styles/app.scss";
|
||||
import "regenerator-runtime/runtime";
|
||||
import axios from "axios";
|
||||
|
||||
export default function Register(): ReactElement {
|
||||
const [isLogged, setIsLogged] = useState(false);
|
||||
const [registerState, setRegisterState] = useState({
|
||||
email: "",
|
||||
});
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const checkUser = async (): Promise<void> => {
|
||||
try {
|
||||
await axios.get(
|
||||
"http://localhost:8080/api/v1/collections/users/me"
|
||||
);
|
||||
setIsLogged(true);
|
||||
} catch (error) {
|
||||
setIsLogged(false);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
void checkUser();
|
||||
}, []);
|
||||
const postRegister = async () => {
|
||||
try {
|
||||
await axios.post(
|
||||
"http://localhost:8080/api/v1/collections/registration-intents",
|
||||
{
|
||||
email: registerState.email,
|
||||
}
|
||||
);
|
||||
void checkUser();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
const notLoggedForm = () => {
|
||||
return (
|
||||
<form>
|
||||
<label htmlFor="email">
|
||||
Adres email
|
||||
<input
|
||||
type="email"
|
||||
name="email"
|
||||
value={registerState.email}
|
||||
onChange={(e) =>
|
||||
setRegisterState({
|
||||
email: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="submit"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
console.log(postRegister());
|
||||
}}
|
||||
>
|
||||
Zaloguj
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Nav isLogged={isLogged} logoutState={() => setIsLogged(false)} />
|
||||
{isLogged ? <h1>Jesteś zalogowany</h1> : notLoggedForm()}
|
||||
</>
|
||||
);
|
||||
}
|
||||
ReactDOM.render(<Register />, document.getElementById("root"));
|
Loading…
Reference in New Issue