import { deleteCookie, getCookie, setCookie } from 'cookies-next' /** * Retrieves authentication data from cookie and returns it as an object. * * @returns {Object|boolean} - Returns the authentication data as an object if available in cookie, otherwise `false`. */ const getAuth = () => { let auth = getCookie('auth') if (auth) return JSON.parse(auth) return false } /** * Sets the authentication data in cookie with the given user data. * * @param {Object} user - The user data to be set as authentication data in cookie. * @returns {boolean} - Returns `true`. */ const setAuth = (user) => { setCookie('auth', JSON.stringify(user)) return true } /** * Deletes the authentication data stored in cookie. * * @returns {boolean} - Returns `true`. */ const deleteAuth = () => { deleteCookie('auth') return true } export { getAuth, setAuth, deleteAuth }