dsql-admin/dsql-app/.local_dist/server/chunks/9922.js

65 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
exports.id = 9922;
exports.ids = [9922];
exports.modules = {
/***/ 9922:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "Z": () => (/* binding */ clientAuthUser)
/* harmony export */ });
/* harmony import */ var _fetchApi__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6729);
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Auth user on client side
* ==============================================================================
* @param {object} params - React ref with current value
* @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").UserType | {} | *>>} params.setUser - React ref with current value
*
* @requires search-field name attribute
*/ function clientAuthUser({ setUser }) {
/**
* Check for user in local storage
*
* @description Preventdefault, declare variables
*/ let localStorageUser = localStorage.getItem("user");
if (localStorageUser) {
try {
setUser(JSON.parse(localStorageUser));
return;
} catch (error) {
setUser({});
return;
}
}
/**
* Fetch User from server
*
* @description Preventdefault, declare variables
*/ (0,_fetchApi__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .Z)("/api/clientSideAuth", {
method: "post",
body: {}
}, true).then((res)=>{
let finalUser = res.user ? res.user : {};
setUser(finalUser);
localStorage.setItem("user", JSON.stringify(finalUser));
// localStorage.setItem("user", JSON.stringify(res.user));
}).catch((error)=>{
console.log(error);
});
} ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/***/ })
};
;