get logged in user id
This commit is contained in:
parent
226d403733
commit
1c85863245
@ -8,6 +8,10 @@ import hsbcLogo from "../../assets/logo-png.png";
|
|||||||
import zoomLogo from "../../assets/zoom.png";
|
import zoomLogo from "../../assets/zoom.png";
|
||||||
import LoginIcon from "@mui/icons-material/Login";
|
import LoginIcon from "@mui/icons-material/Login";
|
||||||
import useAuth from "../../hooks/useAuth";
|
import useAuth from "../../hooks/useAuth";
|
||||||
|
import { store } from "../../redux/store";
|
||||||
|
import { fetchFavorites } from "../../redux/slices/favoritesSlice";
|
||||||
|
import { fetchMeetings } from "../../redux/slices/meetingsAndUserStatusSlice";
|
||||||
|
import { fetchUsers } from "../../redux/slices/usersSlice";
|
||||||
|
|
||||||
interface LocationState {
|
interface LocationState {
|
||||||
from: { pathname: string };
|
from: { pathname: string };
|
||||||
@ -20,7 +24,7 @@ const Login: React.FC = () => {
|
|||||||
const state = location.state as LocationState;
|
const state = location.state as LocationState;
|
||||||
const from = state?.from?.pathname || "/";
|
const from = state?.from?.pathname || "/";
|
||||||
|
|
||||||
const [username, setUsername] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
// const [errMsg, setErrMsg] = useState('');
|
// const [errMsg, setErrMsg] = useState('');
|
||||||
|
|
||||||
@ -35,14 +39,34 @@ const Login: React.FC = () => {
|
|||||||
// setErrMsg('');
|
// setErrMsg('');
|
||||||
// }, [user, pwd])
|
// }, [user, pwd])
|
||||||
|
|
||||||
const handleLogin = () => {
|
const handleLogin = async(e: React.SyntheticEvent) => {
|
||||||
if (username === "" && password === "") {
|
e.preventDefault();
|
||||||
// setAuth({username: username, isLoggedIn: true});
|
if (email === "" && password === "") {
|
||||||
setAuth["username"] = username;
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
setAuth["email"] = email;
|
||||||
setAuth["isLoggedIn"] = true;
|
setAuth["isLoggedIn"] = true;
|
||||||
|
|
||||||
|
store.dispatch(fetchMeetings(logedInUserid));
|
||||||
|
store.dispatch(fetchUsers(logedInUserid));
|
||||||
|
store.dispatch(fetchFavorites(logedInUserid));
|
||||||
|
|
||||||
navigate(from, { replace: true });
|
navigate(from, { replace: true });
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
setUsername("");
|
}
|
||||||
|
setEmail("");
|
||||||
setPassword("");
|
setPassword("");
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,13 +76,13 @@ const Login: React.FC = () => {
|
|||||||
<img className="login-logo" src={hsbcLogo} alt="HSBC Logo" />
|
<img className="login-logo" src={hsbcLogo} alt="HSBC Logo" />
|
||||||
{/* <p ref={errRef} className={errMsg ? "errmsg" : "offscreen"} aria-live="assertive">{errMsg}</p> */}
|
{/* <p ref={errRef} className={errMsg ? "errmsg" : "offscreen"} aria-live="assertive">{errMsg}</p> */}
|
||||||
<TextField
|
<TextField
|
||||||
className="username-input"
|
className="email-input"
|
||||||
id="outlined-basic"
|
id="outlined-basic"
|
||||||
label="Username"
|
label="Email"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
placeholder="Username"
|
placeholder="Email"
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setUsername(event.target.value);
|
setEmail(event.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
import { createContext, useState } from "react";
|
import { createContext, useState } from "react";
|
||||||
|
|
||||||
interface loginInfo {
|
interface loginInfo {
|
||||||
username: string;
|
email: string;
|
||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<loginInfo>({
|
const AuthContext = createContext<loginInfo>({
|
||||||
username: "",
|
email: "",
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
||||||
const [auth] = useState<loginInfo>({ username: "", isLoggedIn: false });
|
const [auth] = useState<loginInfo>({ email: "", isLoggedIn: false });
|
||||||
|
|
||||||
return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>;
|
return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { useContext } from "react";
|
|||||||
import AuthContext from "../context/AuthProvider";
|
import AuthContext from "../context/AuthProvider";
|
||||||
|
|
||||||
interface loginInfo {
|
interface loginInfo {
|
||||||
username: string;
|
email: string;
|
||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,13 +4,10 @@ import "./style/App.css";
|
|||||||
import { AuthProvider } from "./context/AuthProvider";
|
import { AuthProvider } from "./context/AuthProvider";
|
||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import { store } from "./redux/store";
|
import { store } from "./redux/store";
|
||||||
import { fetchFavorites } from "./redux/slices/favoritesSlice";
|
|
||||||
import { fetchMeetings } from "./redux/slices/meetingsAndUserStatusSlice";
|
|
||||||
import { fetchUsers } from "./redux/slices/usersSlice";
|
|
||||||
|
|
||||||
store.dispatch(fetchMeetings(""));
|
// store.dispatch(fetchMeetings(""));
|
||||||
store.dispatch(fetchUsers(""));
|
// store.dispatch(fetchUsers(""));
|
||||||
store.dispatch(fetchFavorites(""));
|
// store.dispatch(fetchFavorites(""));
|
||||||
|
|
||||||
const Index: React.FC = () => {
|
const Index: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user