atmosware-next-cookie-manage

3.1.5 • Public • Published

atmosware-cookie-manage

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.

Available Methods

1. useCookieManage.createCookieFromServer(key, value)

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");

2. useCookieManage.deleteCookieFromServer(key)

This method deletes a cookie from the server.

  • Parameters:

    • key (string): The name of the cookie to be deleted.
  • Usage:

    useCookieManage.deleteCookieFromServer("token");

3. useCookieManage.getCookieFromServer(key)

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.
  • Usage:

    const token = useCookieManage.getCookieFromServer("token");

4. useCookieManage.hasCookieFromServer(key)

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");

Client-Side Cookie Management

To handle cookies on the client side, you can destructure the token and setClientToken from useCookieManage().

Example:

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.

Readme

Keywords

Package Sidebar

Install

npm i atmosware-next-cookie-manage

Weekly Downloads

2

Version

3.1.5

License

ISC

Unpacked Size

4.26 kB

Total Files

4

Last publish

Collaborators

  • kagancoskun
  • irmegndgn