npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cookiz-auth

v1.0.3

Published

React cookie-based authentication with HTTP-only cookies and customizable endpoints.

Readme

cookiz-auth

npm version license GitHub issues GitHub stars

A cookie-based authentication library for React that uses HTTP-only cookies for secure session handling.
Built to be backend-agnostic, simple to integrate, and secure by default.


✨ Features

  • Secure HTTP-only cookie authentication (no localStorage token handling)
  • Customizable endpoints (/login, /logout, /me, /refresh)
  • Auth context + useAuth() hook for user session state
  • TypeScript support out-of-the-box
  • Framework agnostic backend support (Node.js, Laravel, Django, Go, etc.)
  • Plug & Play with minimal setup

📦 Installation

npm install cookiz-auth
# or
yarn add cookiz-auth

🚀 Quick Start

import React from "react";
import { AuthProvider } from "cookiz-auth";

const App = () => (
  <AuthProvider>
    <YourAppComponents />
  </AuthProvider>
);

🛠️ Configuration

// default base URL is http://localhost:4000
// you can customize the endpoints as needed
// to set BASE_URL, you can use environment variables or pass it directly
<AuthProvider
  endpoints={{
    login: "/api/auth/login", // Endpoint for user login
    logout: "/api/auth/logout", // Endpoint for user logout
    user: "/api/auth/user", // Endpoint to get the current user
    refresh: "/api/auth/refresh", // Endpoint to refresh the user session
    baseUrl: "http://localhost:4000", // Base URL for your API
  }}
>
  <YourAppComponents />
</AuthProvider>

🧑‍💻 Usage

import { useAuth } from "cookiz-auth";

const Dashboard = () => {
  const { user, login, logout, loading } = useAuth();

  if (loading) return <p>Loading...</p>;

  return user ? (
    <>
      <h3>Welcome, {user.name}!</h3>
      <button onClick={logout}>Logout</button>
    </>
  ) : (
    <button
      onClick={() => login({ email: "[email protected]", password: "123456" })}
    >
      Login
    </button>
  );
};

protected Routes

import { useAuth } from "cookiz-auth";
import { Navigate } from "react-router-dom";

const ProtectedRoute = ({ children }: { children: JSX.Element }) => {
  const { user, loading } = useAuth();
  if (loading) return <p>Loading...</p>;
  return user ? children : <Navigate to="/login" />;
};

// Usage
<Route
  path="/dashboard"
  element={
    <ProtectedRoute>
      <Dashboard />
    </ProtectedRoute>
  }
/>;

🛠️ Backend requirements

  • Session Management: Your backend should support session management using HTTP-only cookies.
  • CORS: Ensure your API has the appropriate CORS headers to allow requests from your frontend.
  • Endpoints: Implement the necessary authentication endpoints (/login, /logout, /me, /refresh) as specified in the configuration.

Your backend must set HTTP-only cookies:

// Example in Express.js
app.post("/login", (req, res) => {
  // Authenticate user...
  res.cookie("session", "your-session-id", {
    httpOnly: true,
    secure: process.env.NODE_ENV === "production", // Use secure cookies in production
    sameSite: "Strict", // Adjust as needed
  });
  res.json({ success: true });
});

// cors

app.use(
  cors({
    origin: "http://localhost:3000", // Your frontend URL
    credentials: true, // Allow cookies to be sent
  })
);

// development and contribution

🛠️ Development and Contribution

To contribute to cookiz-auth, follow these steps:

  1. Clone the repository:

    git clone https://github.com/Nekromenzer/cookiz.git
  2. Install dependencies:

    cd cookiz-auth
    npm install
  3. Make your changes and test them locally.

  4. Run the development server:

    npm run dev
  5. Build the project:

    npm run build
  6. ** Run locally in another project**:

    npm link

    Then in your project:

    npm link cookiz-auth
  7. Fork the repository on GitHub and create a new branch for your feature or bug fix.

  8. Submit a pull request with a clear description of your changes.