Compare commits

..

1 Commits

Author SHA1 Message Date
victorAnumudu f2e278a8cf expires login session after 5 mins 2023-01-30 11:41:49 +01:00
5 changed files with 34 additions and 51 deletions
-1
View File
@@ -9,6 +9,5 @@ REACT_APP_APPSITE=" https://myfitapp.mermsemr.com"
REACT_APP_AUX_ENDPOINT = "https://devapi.mermsemr.com/en/desktop/api/v2/myfit" REACT_APP_AUX_ENDPOINT = "https://devapi.mermsemr.com/en/desktop/api/v2/myfit"
REACT_APP_USERS_ENDPOINT = "https://devapi.mermsemr.com/en/desktop/api/v2/myfituser" REACT_APP_USERS_ENDPOINT = "https://devapi.mermsemr.com/en/desktop/api/v2/myfituser"
# REACT_APP_PASSWORD_ENDPOINT = "https://devapi.mermsemr.com/en/desktop/api/v2/myfituser/resetpass"
REACT_APP_SESSION_EXPIRE_MINUTES = 5 REACT_APP_SESSION_EXPIRE_MINUTES = 5
@@ -1,40 +1,10 @@
import React, { useState, useEffect } from "react"; import React from "react";
import { Link, useNavigate } from 'react-router-dom'; import { Link } from 'react-router-dom';
import titleShape from "../../../assets/images/shape/title-shape-two.svg"; import titleShape from "../../../assets/images/shape/title-shape-two.svg";
import InputCom from "../../Helpers/Inputs/InputCom"; import InputCom from "../../Helpers/Inputs/InputCom";
import AuthLayout from "../AuthLayout"; import AuthLayout from "../AuthLayout";
export default function ForgotPassword() { export default function ForgotPassword() {
const navigate = useNavigate();
const [validation, setValidation] = useState("")
const [buttonDisabled, setButtonDisabled] = useState(true)
// email
const [email, setEmail] = useState("");
const handleEmail = (e) => {
setEmail(e.target.value);
};
function validationChecker(email) {
const emailCheck = /^[^0-9][a-zA-Z0-9._%+-]+@[a-zA-Z]+(\.[a-zA-Z]+)+$/;
if (email === "") {
setValidation("email is required");
} else if (!email.match(emailCheck)) {
setValidation('Please input a valid email address');
} else {
setValidation("");
setButtonDisabled(false)
}
}
useEffect(() => {
validationChecker(email)
}, [email])
return ( return (
<> <>
<AuthLayout <AuthLayout
@@ -58,24 +28,19 @@ export default function ForgotPassword() {
name="email" name="email"
type="email" type="email"
iconName="message" iconName="message"
inputHandler={handleEmail}
value={email}
/> />
{validation && <p className="my-5 font-bold text-red-500">{validation}</p>}
</div> </div>
<div className="signin-area mb-3.5"> <div className="signin-area mb-3.5">
<a
<button href="/verify-you"
className="w-full rounded-[50px] mb-5 h-[58px] text-xl text-white font-bold flex justify-center bg-purple items-center" className="w-full rounded-[50px] mb-5 h-[58px] text-xl text-white font-bold flex justify-center bg-purple items-center"
disabled={buttonDisabled}
onClick={() => navigate("/verify-you")}
> >
Send Code Send Code
</button> </a>
<Link to="/" <Link to="/"
className="my-40 font-bold flex justify-center text-red-500 items-center" className=" my-40 font-bold flex justify-center text-red-500 items-center"
> >
Back to Home Back to Home
</Link> </Link>
+1 -1
View File
@@ -21,7 +21,7 @@ export default function Layout({ children }) {
const navigate = useNavigate(); const navigate = useNavigate();
const logOut = () => { const logOut = () => {
localStorage.removeItem("email"); localStorage.removeItem("email");
localStorage.clear(); localStorage.removeItem('session_token');
toast.success("Come Back Soon", { toast.success("Come Back Soon", {
icon: `🙂`, icon: `🙂`,
}); });
+3 -6
View File
@@ -15,7 +15,6 @@ class usersService {
return this.postAuxEnd("/login", reqData); return this.postAuxEnd("/login", reqData);
} }
getUserReminders(){ getUserReminders(){
return this.getAuxEnd("/reminders", null); return this.getAuxEnd("/reminders", null);
} }
@@ -56,16 +55,14 @@ class usersService {
}); });
} }
postAuxEnd(uri, reqData) { postAuxEnd(uri, reqData) {
const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri; const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
const token = '..your token..' const session_token = localStorage.getItem("session_token");
let axiosConfig = { let axiosConfig = {
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json;charset=UTF-8', 'Content-Type': 'application/json;charset=UTF-8',
'Authorization': `Basic ${token}`, 'Authorization': `Basic ${session_token}`,
} }
}; };
//Access-Control-Allow-Origin //Access-Control-Allow-Origin
@@ -75,7 +72,7 @@ class usersService {
}; };
// Axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8'; // Axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8';
// Axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*'; //,axiosConfig // Axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*'; //,axiosConfig
return Axios.post(endPoint, reqData) return Axios.post(endPoint, reqData,axiosConfig)
.then((response) => { .then((response) => {
console.log(response); console.log(response);
// res = response; // res = response;
+23 -1
View File
@@ -1,7 +1,29 @@
import React from "react"; import React, {useEffect} from "react";
import Home from "../components/Home"; import Home from "../components/Home";
import { useNavigate } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { toast } from "react-toastify";
export default function HomePages() { export default function HomePages() {
const { drawer } = useSelector((state) => state.drawer);
const dispatch = useDispatch();
const navigate = useNavigate();
const logOut = () => {
localStorage.removeItem("email");
localStorage.removeItem('session_token');
toast.success("Come Back Soon", {
icon: `🙂`,
});
navigate("/login", { replace: true });
};
useEffect(()=>{
setTimeout(()=>{
logOut()
}, 300000) //expires user login session after 5 minutes
},[])
return ( return (
<> <>
<Home /> <Home />