diff options
Diffstat (limited to 'src/core/utils/auth.js')
| -rw-r--r-- | src/core/utils/auth.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/core/utils/auth.js b/src/core/utils/auth.js index 13e0e79d..cddff2b8 100644 --- a/src/core/utils/auth.js +++ b/src/core/utils/auth.js @@ -1,18 +1,32 @@ 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) - } + 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 |
