user session
parent
c39d739ade
commit
9df013f603
|
@ -1,4 +1,4 @@
|
||||||
import { createContext } from "react";
|
import { createContext, useState } from "react";
|
||||||
|
|
||||||
export const Constants = {
|
export const Constants = {
|
||||||
API_ADDRESS: "http://localhost:8080/v1",
|
API_ADDRESS: "http://localhost:8080/v1",
|
||||||
|
@ -13,3 +13,26 @@ export const ClientUserDataPreview = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export let ClientUserData = createContext(null);
|
export let ClientUserData = createContext(null);
|
||||||
|
|
||||||
|
export function UseUserSession() {
|
||||||
|
const getUserSession = () => {
|
||||||
|
return JSON.parse(localStorage.getItem("session"));
|
||||||
|
};
|
||||||
|
|
||||||
|
const [userSession, setUserSession] = useState(getUserSession());
|
||||||
|
|
||||||
|
const saveUserSession = (session) => {
|
||||||
|
setUserSession(session);
|
||||||
|
|
||||||
|
if (session === undefined) {
|
||||||
|
localStorage.removeItem("session");
|
||||||
|
} else {
|
||||||
|
localStorage.setItem("session", JSON.stringify(session));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
setUserSession: saveUserSession,
|
||||||
|
userSession,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue