implemented vite caching and added adaptive agriculture logos and manifest

This commit is contained in:
Carter 2025-02-27 12:06:41 -06:00
parent 9633fb7bb6
commit 1979976ad5
19 changed files with 4924 additions and 706 deletions

View file

@ -34,7 +34,7 @@ export const HTTPContext = createContext<IHTTPContext>({} as IHTTPContext);
export default function HTTPProvider(props: Props) {
const { children, token } = props;
const { isAuthenticated } = useAuth0();
const { isAuthenticated, /*loginWithRedirect,*/ loginWithPopup } = useAuth0();
const defaultOptions = (demo: boolean = false) => {
if (demo || !isAuthenticated || !token) {
@ -54,7 +54,36 @@ export default function HTTPProvider(props: Props) {
return config;
};
function isTokenExpired(token: string): boolean {
try {
// Split the token and decode the payload (second part)
const payloadBase64 = token.split('.')[1];
const decodedPayload = atob(payloadBase64); // Decode base64
const payload = JSON.parse(decodedPayload);
// Get expiration time (in seconds)
const exp = payload.exp;
if (!exp) return true; // No exp field? Treat as expired
// Current time in seconds
const now = Math.floor(Date.now() / 1000);
// Compare
return now >= exp;
} catch (error) {
console.error("Invalid token format:", error);
return true; // Err on the side of caution if decoding fails
}
}
function get<T>(url: string, spreadOptions?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
if (isTokenExpired(token)) {
console.log("token expired")
loginWithPopup()
} else {
console.log("token is fine")
}
return axios.get(url, {...defaultOptions(), ...spreadOptions});
}