diff --git a/.env b/.env index 20f9638..740a702 100644 --- a/.env +++ b/.env @@ -14,4 +14,7 @@ VITE_APP_PREVIEW_DOCS_URL=https://www.wrenchboard.com/ VITE_APP_THEME_API_URL=https://api.wrenchboard/api/api # main url -VITE_APP_MAINSITE_URL=https://www.wrenchboard.com \ No newline at end of file +VITE_APP_MAINSITE_URL=https://www.wrenchboard.com +VITE_APP_SESSION_EXPIRE_CHECKER=60000 +VITE_APP_SESSION_EXPIRE_MINUTES=900000 +VITE_APP_WRENCH_IDENTITY_SITE=https://dev-ident.wrenchboard.com/ \ No newline at end of file diff --git a/.env.development b/.env.development index a9607c4..63e7500 100644 --- a/.env.development +++ b/.env.development @@ -11,4 +11,10 @@ VITE_APP_PURCHASE_URL=https://themeforest.net/item/metronic-responsive-admin-das VITE_APP_PREVIEW_URL=https://preview.keenthemes.com/metronic8/react/demo1/ VITE_APP_PREVIEW_REACT_URL=https://preview.keenthemes.com/metronic8/react VITE_APP_PREVIEW_DOCS_URL=https://preview.keenthemes.com/metronic8/react/docs -VITE_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api \ No newline at end of file +VITE_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api + +# main url +VITE_APP_MAINSITE_URL=https://www.wrenchboard.com +VITE_APP_SESSION_EXPIRE_CHECKER=60000 +VITE_APP_SESSION_EXPIRE_MINUTES=900000 +VITE_APP_WRENCH_IDENTITY_SITE=https://dev-ident.wrenchboard.com/ \ No newline at end of file diff --git a/.env.production b/.env.production index a9607c4..63e7500 100644 --- a/.env.production +++ b/.env.production @@ -11,4 +11,10 @@ VITE_APP_PURCHASE_URL=https://themeforest.net/item/metronic-responsive-admin-das VITE_APP_PREVIEW_URL=https://preview.keenthemes.com/metronic8/react/demo1/ VITE_APP_PREVIEW_REACT_URL=https://preview.keenthemes.com/metronic8/react VITE_APP_PREVIEW_DOCS_URL=https://preview.keenthemes.com/metronic8/react/docs -VITE_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api \ No newline at end of file +VITE_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api + +# main url +VITE_APP_MAINSITE_URL=https://www.wrenchboard.com +VITE_APP_SESSION_EXPIRE_CHECKER=60000 +VITE_APP_SESSION_EXPIRE_MINUTES=900000 +VITE_APP_WRENCH_IDENTITY_SITE=https://dev-ident.wrenchboard.com/ \ No newline at end of file diff --git a/src/app/modules/auth/components/Login.tsx b/src/app/modules/auth/components/Login.tsx index 5055aab..4f8036d 100644 --- a/src/app/modules/auth/components/Login.tsx +++ b/src/app/modules/auth/components/Login.tsx @@ -7,6 +7,8 @@ import { getUserByToken, login } from "../core/_requests"; import { toAbsoluteUrl } from "../../../../_metronic/helpers"; import { useAuth } from "../core/Auth"; +const SOCIAL_LINK = import.meta.env.VITE_APP_WRENCH_IDENTITY_SITE; + const loginSchema = Yup.object().shape({ email: Yup.string() .email("Wrong email format") @@ -25,7 +27,7 @@ const initialValues = { }; // email: "admin@demo.com", - // password: "demo", +// password: "demo", /* Formik+YUP+Typescript: https://jaredpalmer.com/formik/docs/tutorial#getfieldprops @@ -75,7 +77,9 @@ export function Login() {
{/* begin::Google link */} {/* begin::Google link */} Logo - Logo - Sign in with Apple + Sign in with Facebook {/* end::Google link */}
@@ -126,13 +127,11 @@ export function Login() {
{formik.status}
- ) : ( - //
- - //
+ ) : //
- null - )} + //
+ + null} {/* begin::Form group */}
diff --git a/src/app/modules/auth/core/Auth.tsx b/src/app/modules/auth/core/Auth.tsx index 2f7ee6e..cc79dde 100644 --- a/src/app/modules/auth/core/Auth.tsx +++ b/src/app/modules/auth/core/Auth.tsx @@ -3,6 +3,7 @@ import { FC, useState, useEffect, + useCallback, createContext, useContext, Dispatch, @@ -39,6 +40,15 @@ const useAuth = () => { const AuthProvider: FC = ({ children }) => { const [auth, setAuth] = useState(authHelper.getAuth()); const [currentUser, setCurrentUser] = useState(); + const [lastActivityTime, setLastActivityTime] = useState(Date.now()); + + let checkExpirationInMinutes: number = Number( + import.meta.env.VITE_APP_SESSION_EXPIRE_MINUTES + ); + let expirationChecker: number = Number( + import.meta.env.VITE_APP_SESSION_EXPIRE_CHECKER + ); + const saveAuth = (auth: AuthModel | undefined) => { setAuth(auth); if (auth) { @@ -53,6 +63,42 @@ const AuthProvider: FC = ({ children }) => { setCurrentUser(undefined); }; + useEffect((): any => { + const expireSession = () => { + localStorage.removeItem("wrenchboard-agent-auth-details"); + logout(); + }; + + const checkInactivity = setInterval(() => { + let currentTime: number = Date.now(); + let checkLastActivityTime: number = lastActivityTime; + + if (currentTime - checkLastActivityTime > checkExpirationInMinutes) { + expireSession(); + } + }, expirationChecker); + + // cleaning up listeners + return () => { + clearInterval(checkInactivity); + }; + }, [lastActivityTime]); + + // Reset last activity time on user input + const resetTime = useCallback(() => { + setLastActivityTime(Date.now()); + }, []); + + useEffect(() => { + window.addEventListener("mousemove", resetTime); + window.addEventListener("keydown", resetTime); + + return () => { + window.removeEventListener("mousemove", resetTime); + window.removeEventListener("keydown", resetTime); + }; + }, [resetTime]); + return ( { if (!localStorage) { return