blob: a7244747522cae78fdfe4aecc91e8195e747da0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import { deleteCookie, getCookie, setCookie } from 'cookies-next'
import { signOut } from 'next-auth/react'
/**
* 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 = async() => {
// await signOut()
deleteCookie('auth')
return true
}
export { getAuth, setAuth, deleteAuth }
|