fix: restrict user from logging in when next renewal date is expired even when route is entered directly

This commit is contained in:
prafull-opensignlabs
2024-03-27 13:11:20 +05:30
parent adbf1fe1e0
commit 3115ff3e2a
3 changed files with 38 additions and 31 deletions
+3 -22
View File
@@ -34,7 +34,6 @@ const HomeLayout = () => {
});
if (user) {
checkIsSubscribed();
setIsLoader(false);
} else {
setIsUserValid(false);
}
@@ -48,10 +47,6 @@ const HomeLayout = () => {
async function checkIsSubscribed() {
const currentUser = Parse.User.current();
// const userSettings = appInfo.settings;
// const setting = userSettings.find((x) => x.role === _currentRole);
// const redirectUrl =
// location?.state?.from || `/${setting.pageType}/${setting.pageId}`;
const user = await Parse.Cloud.run("getUserDetails", {
email: currentUser.get("email")
});
@@ -59,24 +54,12 @@ const HomeLayout = () => {
if (_user.TenantId) {
localStorage.setItem("TenetId", _user.TenantId.objectId);
}
// localStorage.setItem("PageLanding", setting.pageId);
// localStorage.setItem("defaultmenuid", setting.menuId);
// localStorage.setItem("pageType", setting.pageType);
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
// const LocalUserDetails = {
// name: _user.Name,
// email: _user.Email,
// phone: _user.Phone,
// company: _user.Company
// };
// localStorage.setItem("userDetails", JSON.stringify(LocalUserDetails));
const billingDate = _user.Next_billing_date && _user.Next_billing_date;
if (billingDate) {
if (billingDate > new Date()) {
// localStorage.removeItem("userDetails");
// Redirect to the appropriate URL after successful login
// navigate(redirectUrl);
setIsUserValid(true);
setIsLoader(false);
return true;
} else {
navigate(`/subscription`);
@@ -86,9 +69,8 @@ const HomeLayout = () => {
}
} else {
setIsUserValid(true);
setIsLoader(false);
return true;
// Redirect to the appropriate URL after successful login
// navigate(redirectUrl);
}
}
const showSidebar = () => {
@@ -244,7 +226,7 @@ const HomeLayout = () => {
return (
<div>
<div className="sticky top-0 z-50">
<Header showSidebar={showSidebar} />
{!isLoader && <Header showSidebar={showSidebar} />}
</div>
{isUserValid ? (
<>
@@ -269,7 +251,6 @@ const HomeLayout = () => {
<>
<div className="flex md:flex-row flex-col z-50">
<Sidebar isOpen={isOpen} closeSidebar={closeSidebar} />
<div
id="renderList"
className="relative h-screen flex flex-col justify-between w-full overflow-y-auto"
+8 -8
View File
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router";
// import { useNavigate } from "react-router";
import { NavLink } from "react-router-dom";
import checkmark from "../assets/images/checkmark.png";
import plansArr from "../json/plansArr.json";
@@ -13,7 +13,7 @@ const listItemStyle = {
};
const PlanSubscriptions = () => {
const navigate = useNavigate();
// const navigate = useNavigate();
const [yearlyVisible, setYearlyVisible] = useState(false);
const [isLoader, setIsLoader] = useState(true);
@@ -35,12 +35,12 @@ const PlanSubscriptions = () => {
company +
phone;
useEffect(() => {
if (localStorage.getItem("accesstoken")) {
// if (localStorage.getItem("accesstoken")) {
setIsLoader(false);
setYearlyVisible(false);
} else {
navigate("/", { replace: true });
}
// } else {
// navigate("/", { replace: true });
// }
// eslint-disable-next-line
}, []);
@@ -108,7 +108,7 @@ const PlanSubscriptions = () => {
: ""
} text-sm text-center my-2`}
>
<p
<div
style={{
backgroundColor: item.subtitlecolor
? item.subtitlecolor
@@ -124,7 +124,7 @@ const PlanSubscriptions = () => {
) : (
<span>{item.subtitle}</span>
)}
</p>
</div>
</div>
</div>
+27 -1
View File
@@ -15,7 +15,7 @@ const Validate = () => {
sessionToken: localStorage.getItem("accesstoken")
});
if (user) {
setIsUserValid(true);
checkIsSubscribed();
} else {
setIsUserValid(false);
}
@@ -24,7 +24,33 @@ const Validate = () => {
setIsUserValid(false);
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
async function checkIsSubscribed() {
const currentUser = Parse.User.current();
console.log("currentUser ", currentUser)
const user = await Parse.Cloud.run("getUserDetails", {
email: currentUser.get("email")
});
const _user = user?.toJSON();
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
const billingDate = _user.Next_billing_date && _user.Next_billing_date;
if (billingDate) {
if (billingDate > new Date()) {
setIsUserValid(true);
return true;
} else {
// navigate(`/subscription`);
}
} else {
// navigate(`/subscription`);
}
} else {
setIsUserValid(true);
}
}
const handleLoginBtn = () => {
try {
Parse.User.logOut();