atmosware-cookie-manage
is a utility for managing cookies in a Next.js environment. It allows you to create, delete, retrieve, and check for cookies both on the server and client side.
This method creates a cookie on the server.
-
Parameters:
-
key
(string): The name of the cookie. -
value
(string): The value to be stored in the cookie.
-
-
Usage:
useCookieManage.createCookieFromServer("token", "abc123");
This method deletes a cookie from the server.
-
Parameters:
-
key
(string): The name of the cookie to be deleted.
-
-
Usage:
useCookieManage.deleteCookieFromServer("token");
This method retrieves the value of a cookie from the server.
-
Parameters:
-
key
(string): The name of the cookie to retrieve.
-
-
Returns:
- The value of the cookie if found, otherwise
null
.
- The value of the cookie if found, otherwise
-
Usage:
const token = useCookieManage.getCookieFromServer("token");
This method checks if a cookie exists on the server.
-
Parameters:
-
key
(string): The name of the cookie to check.
-
-
Returns:
-
true
if the cookie exists,false
otherwise.
-
-
Usage:
const hasToken = useCookieManage.hasCookieFromServer("token");
To handle cookies on the client side, you can destructure the token
and setClientToken
from useCookieManage()
.
const { token, setClientToken } = useCookieManage();
// Setting a new token value
setClientToken("newTokenValue");
-
token
: Holds the current value of the token stored in cookies. -
setClientToken(value)
: Allows you to set a new token value in the client-side cookies.
This makes cookie management seamless in both server and client contexts within your Next.js application.