added the session countdown and added facebook logo and link

This commit was merged in pull request #6.
This commit is contained in:
Ebube
2024-02-19 23:47:10 +01:00
parent 27f63e4b80
commit 4b738aa8cd
6 changed files with 81 additions and 21 deletions
+4 -1
View File
@@ -14,4 +14,7 @@ VITE_APP_PREVIEW_DOCS_URL=https://www.wrenchboard.com/
VITE_APP_THEME_API_URL=https://api.wrenchboard/api/api VITE_APP_THEME_API_URL=https://api.wrenchboard/api/api
# main url # main url
VITE_APP_MAINSITE_URL=https://www.wrenchboard.com 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/
+7 -1
View File
@@ -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_URL=https://preview.keenthemes.com/metronic8/react/demo1/
VITE_APP_PREVIEW_REACT_URL=https://preview.keenthemes.com/metronic8/react 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_PREVIEW_DOCS_URL=https://preview.keenthemes.com/metronic8/react/docs
VITE_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api 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/
+7 -1
View File
@@ -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_URL=https://preview.keenthemes.com/metronic8/react/demo1/
VITE_APP_PREVIEW_REACT_URL=https://preview.keenthemes.com/metronic8/react 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_PREVIEW_DOCS_URL=https://preview.keenthemes.com/metronic8/react/docs
VITE_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api 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/
+16 -17
View File
@@ -7,6 +7,8 @@ import { getUserByToken, login } from "../core/_requests";
import { toAbsoluteUrl } from "../../../../_metronic/helpers"; import { toAbsoluteUrl } from "../../../../_metronic/helpers";
import { useAuth } from "../core/Auth"; import { useAuth } from "../core/Auth";
const SOCIAL_LINK = import.meta.env.VITE_APP_WRENCH_IDENTITY_SITE;
const loginSchema = Yup.object().shape({ const loginSchema = Yup.object().shape({
email: Yup.string() email: Yup.string()
.email("Wrong email format") .email("Wrong email format")
@@ -25,7 +27,7 @@ const initialValues = {
}; };
// email: "admin@demo.com", // email: "admin@demo.com",
// password: "demo", // password: "demo",
/* /*
Formik+YUP+Typescript: Formik+YUP+Typescript:
https://jaredpalmer.com/formik/docs/tutorial#getfieldprops https://jaredpalmer.com/formik/docs/tutorial#getfieldprops
@@ -75,7 +77,9 @@ export function Login() {
<div className="col-md-6"> <div className="col-md-6">
{/* begin::Google link */} {/* begin::Google link */}
<a <a
href="#" href={SOCIAL_LINK}
target="_blank"
rel="noopener noreferrer"
className="btn btn-flex btn-outline btn-text-gray-700 btn-active-color-primary bg-state-light flex-center text-nowrap w-100" className="btn btn-flex btn-outline btn-text-gray-700 btn-active-color-primary bg-state-light flex-center text-nowrap w-100"
> >
<img <img
@@ -93,20 +97,17 @@ export function Login() {
<div className="col-md-6"> <div className="col-md-6">
{/* begin::Google link */} {/* begin::Google link */}
<a <a
href="#" href={SOCIAL_LINK}
target="_blank"
rel="noopener noreferrer"
className="btn btn-flex btn-outline btn-text-gray-700 btn-active-color-primary bg-state-light flex-center text-nowrap w-100" className="btn btn-flex btn-outline btn-text-gray-700 btn-active-color-primary bg-state-light flex-center text-nowrap w-100"
> >
<img <img
alt="Logo" alt="Logo"
src={toAbsoluteUrl("media/svg/brand-logos/apple-black.svg")} src={toAbsoluteUrl("media/svg/brand-logos/facebook-4.svg")}
className="theme-light-show h-15px me-3" className="h-15px me-3"
/> />
<img Sign in with Facebook
alt="Logo"
src={toAbsoluteUrl("media/svg/brand-logos/apple-black-dark.svg")}
className="theme-dark-show h-15px me-3"
/>
Sign in with Apple
</a> </a>
{/* end::Google link */} {/* end::Google link */}
</div> </div>
@@ -126,13 +127,11 @@ export function Login() {
<div className="mb-lg-15 alert alert-danger"> <div className="mb-lg-15 alert alert-danger">
<div className="alert-text font-weight-bold">{formik.status}</div> <div className="alert-text font-weight-bold">{formik.status}</div>
</div> </div>
) : ( ) : // <div className="mb-10 bg-light-info p-8 rounded">
// <div className="mb-10 bg-light-info p-8 rounded">
// </div>
null // </div>
)}
null}
{/* begin::Form group */} {/* begin::Form group */}
<div className="fv-row mb-8"> <div className="fv-row mb-8">
+46
View File
@@ -3,6 +3,7 @@ import {
FC, FC,
useState, useState,
useEffect, useEffect,
useCallback,
createContext, createContext,
useContext, useContext,
Dispatch, Dispatch,
@@ -39,6 +40,15 @@ const useAuth = () => {
const AuthProvider: FC<WithChildren> = ({ children }) => { const AuthProvider: FC<WithChildren> = ({ children }) => {
const [auth, setAuth] = useState<AuthModel | undefined>(authHelper.getAuth()); const [auth, setAuth] = useState<AuthModel | undefined>(authHelper.getAuth());
const [currentUser, setCurrentUser] = useState<UserModel | undefined>(); const [currentUser, setCurrentUser] = useState<UserModel | undefined>();
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) => { const saveAuth = (auth: AuthModel | undefined) => {
setAuth(auth); setAuth(auth);
if (auth) { if (auth) {
@@ -53,6 +63,42 @@ const AuthProvider: FC<WithChildren> = ({ children }) => {
setCurrentUser(undefined); 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 ( return (
<AuthContext.Provider <AuthContext.Provider
value={{ auth, saveAuth, currentUser, setCurrentUser, logout }} value={{ auth, saveAuth, currentUser, setCurrentUser, logout }}
+1 -1
View File
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import {AuthModel} from './_models' import {AuthModel} from './_models'
const AUTH_LOCAL_STORAGE_KEY = 'kt-auth-react-v' const AUTH_LOCAL_STORAGE_KEY = 'wrenchboard-agent-auth-details'
const getAuth = (): AuthModel | undefined => { const getAuth = (): AuthModel | undefined => {
if (!localStorage) { if (!localStorage) {
return return