@peable/services
Advanced tools
Comparing version 0.0.59 to 0.0.60
@@ -13,2 +13,9 @@ interface SessionModel { | ||
} | ||
type SessionState = { | ||
session: SessionModel | null; | ||
status: string; | ||
error: any; | ||
fetchSessionData: () => void; | ||
}; | ||
export declare const useSessionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SessionState>>; | ||
declare function usePeableSession(): { | ||
@@ -15,0 +22,0 @@ session: SessionModel | null; |
@@ -1,38 +0,22 @@ | ||
import { useState, useEffect } from "react"; | ||
import { useEffect } from "react"; | ||
import axios from "axios"; | ||
import Cookies from "js-cookie"; | ||
import { create } from "zustand"; | ||
export const useSessionStore = create((set) => ({ | ||
session: null, | ||
status: "loading", | ||
error: null, | ||
fetchSessionData: async () => { | ||
try { | ||
set({ status: "loading" }); | ||
const response = await axios.get("http://localhost:3001/api/session/dsfuhfsdiuhfiusdhfuisdhfiush"); | ||
set({ session: response.data, status: "success" }); | ||
} | ||
catch (error) { | ||
set({ error, status: "error" }); | ||
} | ||
}, | ||
})); | ||
function usePeableSession() { | ||
const [status, setStatus] = useState("loading"); | ||
const [error, setError] = useState(null); | ||
const [session, setSessionData] = useState(null); | ||
const { session, status, error, fetchSessionData } = useSessionStore(); | ||
useEffect(() => { | ||
const clientKey = Cookies.get("clientKey"); | ||
if (!clientKey) { | ||
const fetchClientKey = async () => { | ||
try { | ||
setStatus("loading"); // Set status to "loading" | ||
const response = await axios.get("https://accounts.peable.co/clientKey.php"); | ||
const data = response.data; | ||
Cookies.set("clientKey", data[0], { expires: 365, path: "" }); | ||
} | ||
catch (error) { | ||
setError(error); | ||
} | ||
}; | ||
fetchClientKey(); | ||
} | ||
}, []); | ||
useEffect(() => { | ||
const fetchSessionData = async () => { | ||
try { | ||
setStatus("loading"); // Set status to "loading" | ||
const response = await axios.get("http://localhost:3001/api/session/dsfuhfsdiuhfiusdhfuisdhfiush"); | ||
setSessionData(response.data); | ||
setStatus("success"); | ||
} | ||
catch (error) { | ||
setError(error); | ||
setStatus("error"); | ||
} | ||
}; | ||
fetchSessionData(); | ||
@@ -39,0 +23,0 @@ }, []); |
{ | ||
"name": "@peable/services", | ||
"version": "0.0.59", | ||
"version": "0.0.60", | ||
"description": "", | ||
@@ -37,4 +37,5 @@ "main": "./dist/index.js", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
"react-dom": "^18.2.0", | ||
"zustand": "^4.5.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4859
6
85
+ Addedzustand@^4.5.2
+ Addeduse-sync-external-store@1.2.2(transitive)
+ Addedzustand@4.5.5(transitive)