login connected backend
This commit is contained in:
parent
1c85863245
commit
759422969a
21
package-lock.json
generated
21
package-lock.json
generated
@ -14,6 +14,7 @@
|
||||
"@mui/material": "^5.4.3",
|
||||
"@reduxjs/toolkit": "^1.8.0",
|
||||
"@types/react-big-calendar": "^0.36.2",
|
||||
"axios": "^0.26.1",
|
||||
"moment": "^2.29.1",
|
||||
"react": "^17.0.2",
|
||||
"react-big-calendar": "^0.39.3",
|
||||
@ -3522,6 +3523,14 @@
|
||||
"lodash": "^4.17.14"
|
||||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.26.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.14.8"
|
||||
}
|
||||
},
|
||||
"node_modules/babel-plugin-dynamic-import-node": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz",
|
||||
@ -7094,7 +7103,6 @@
|
||||
"version": "1.14.9",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
|
||||
"integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@ -15456,6 +15464,14 @@
|
||||
"lodash": "^4.17.14"
|
||||
}
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.26.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.14.8"
|
||||
}
|
||||
},
|
||||
"babel-plugin-dynamic-import-node": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz",
|
||||
@ -18253,8 +18269,7 @@
|
||||
"follow-redirects": {
|
||||
"version": "1.14.9",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
|
||||
"integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==",
|
||||
"dev": true
|
||||
"integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w=="
|
||||
},
|
||||
"forwarded": {
|
||||
"version": "0.2.0",
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
"@mui/material": "^5.4.3",
|
||||
"@reduxjs/toolkit": "^1.8.0",
|
||||
"@types/react-big-calendar": "^0.36.2",
|
||||
"axios": "^0.26.1",
|
||||
"moment": "^2.29.1",
|
||||
"react": "^17.0.2",
|
||||
"react-big-calendar": "^0.39.3",
|
||||
|
||||
5
src/api/axios.tsx
Normal file
5
src/api/axios.tsx
Normal file
@ -0,0 +1,5 @@
|
||||
import axios from "axios";
|
||||
|
||||
export default axios.create({
|
||||
baseURL: "https://g17vmhsvwi.execute-api.us-west-2.amazonaws.com/Prod"
|
||||
});
|
||||
@ -12,6 +12,7 @@ import { store } from "../../redux/store";
|
||||
import { fetchFavorites } from "../../redux/slices/favoritesSlice";
|
||||
import { fetchMeetings } from "../../redux/slices/meetingsAndUserStatusSlice";
|
||||
import { fetchUsers } from "../../redux/slices/usersSlice";
|
||||
import axios from "../../api/axios"
|
||||
|
||||
interface LocationState {
|
||||
from: { pathname: string };
|
||||
@ -41,32 +42,45 @@ const Login: React.FC = () => {
|
||||
|
||||
const handleLogin = async(e: React.SyntheticEvent) => {
|
||||
e.preventDefault();
|
||||
if (email === "" && password === "") {
|
||||
|
||||
try {
|
||||
|
||||
// const response = await axios.post(
|
||||
// 'backend/login',
|
||||
// { email: email, password: password },
|
||||
// { headers: { 'Content-Type': 'application/json' } }
|
||||
// ) // using axios for http requests?
|
||||
const response = { data: { userid: "123456" }}; // delete later
|
||||
|
||||
const logedInUserid = response?.data?.userid;
|
||||
|
||||
if (email === "" && password === "") {
|
||||
setAuth["email"] = email;
|
||||
setAuth["isLoggedIn"] = true;
|
||||
|
||||
store.dispatch(fetchMeetings(logedInUserid));
|
||||
store.dispatch(fetchUsers(logedInUserid));
|
||||
store.dispatch(fetchFavorites(logedInUserid));
|
||||
|
||||
store.dispatch(fetchMeetings(""));
|
||||
store.dispatch(fetchUsers(""));
|
||||
store.dispatch(fetchFavorites(""));
|
||||
navigate(from, { replace: true });
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
'/login',
|
||||
JSON.stringify({ email: email, password: password })
|
||||
// { headers: { 'Content-Type': 'application/json' } }
|
||||
)
|
||||
// const response = { data: { userid: "123456" }}; // delete later
|
||||
|
||||
const logedInUserId = response?.data?.userId;
|
||||
|
||||
console.log(email);
|
||||
console.log(password);
|
||||
console.log(response?.data);
|
||||
|
||||
if (logedInUserId != undefined) {
|
||||
setAuth["email"] = email;
|
||||
setAuth["isLoggedIn"] = true;
|
||||
|
||||
store.dispatch(fetchMeetings(logedInUserId));
|
||||
store.dispatch(fetchUsers(logedInUserId));
|
||||
store.dispatch(fetchFavorites(logedInUserId));
|
||||
navigate(from, { replace: true });
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
setEmail("");
|
||||
setEmail(email);
|
||||
setPassword("");
|
||||
};
|
||||
|
||||
@ -80,6 +94,7 @@ const Login: React.FC = () => {
|
||||
id="outlined-basic"
|
||||
label="Email"
|
||||
variant="outlined"
|
||||
value={email}
|
||||
placeholder="Email"
|
||||
onChange={(event) => {
|
||||
setEmail(event.target.value);
|
||||
@ -90,6 +105,7 @@ const Login: React.FC = () => {
|
||||
id="outlined-basic"
|
||||
label="Password"
|
||||
variant="outlined"
|
||||
value={password}
|
||||
placeholder="Password"
|
||||
type="password"
|
||||
onChange={(event) => {
|
||||
|
||||
Reference in New Issue
Block a user