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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tozielinski/next-upstash-nonce

v1.4.2

Published

Create, store, verify and delete nonces in Redis by Upstash for Next.js

Readme

next-upstash-nonce

License: MIT npm version

Create, store, verify and delete nonces in Redis by Upstash for Next.js and/or secure your API endpoints with a rate limiter

Quick Start

Install the package:

npm install @tozielinski/next-upstash-nonce

Create database

Create a new redis database on upstash

Create a NonceManager Instance

import { NonceManager } from '@tozielinski/next-upstash-nonce'
import { Redis } from "@upstash/redis";

const redis = new Redis({
    url: process.env.UPSTASH_REDIS_REST_URL as string,
    token: process.env.UPSTASH_REDIS_REST_TOKEN as string,
});

export const nonceManager = new NonceManager(redis, {ttlSeconds: 60* 5});

Create a ServerAction, to use it from client side

'use server'

import {nonceManager} from "@/[wherever you store your nonceManager instance]";

export async function createNonce(): Promise<string> {
    return await nonceManager.create();
}

Secure your API endpoint with a Nonce

'use server'

import {NextResponse} from "next/server";
import {nonceManager} from "@/[wherever you store your nonceManager instance]";

export async function POST(req: Request) {
    const nonce: boolean = req.headers.get("x-api-nonce");

    if (!nonce) {
        return NextResponse.json(
            { error: "Missing nonce", valid: false },
            { status: 401 }
        );
    }

    const valid = await nonceManager.verifyAndDelete(nonce);

    // valid will be true if nonce was found and deleted
    // false if nonce was not found or expired
    
    return NextResponse.json({nonce: nonce, valid: valid});
}

or more simple

'use server'
import {NextResponse} from "next/server";
import {nonceManager} from "@/[wherever you store your nonceManager instance]";
import {NonceCheckResult} from "@tozielinski/next-upstash-nonce";

export async function POST(req: Request) {
    const result: NonceCheckResult = await nonceManager.verifyAndDeleteNonceFromRequest(req);

    // result will be {nonce: string, valid: true} or
    // {valid false, reason: string, response: NextResponse}
    // if nonce was not found or expired:
    //
    // export type NonceCheckResult = | {
    //     valid: true;
    //     nonce: string
    // } | {
    //     valid: false;
    //     reason: 'missing-header' | 'invalid-or-expired';
    //     response: Response
    // };
    
    return NextResponse.json({nonce: result.nonce, valid: result.valid});
}

Use it in your client side

'use client'

import {useState} from "react";
import {createNonce} from "@/[wherever you store your server action]";

export default function NonceSecuredComponent() {
    const [running, setRunning] = useState(false);
    const [message, setMessage] = useState('');

    const handleClick = async () => {
        if (running) return;
        setRunning(true);
        setMessage("Starting SSA...");

        const nonce = await createNonce();

        const res = await fetch('/api/[name of your API endpoint]', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'X-API-Nonce': nonce,
            },
            body: JSON.stringify({success: true}),
        });

        if (res.ok) {
            const data = await res.json();
            setMessage(`Nonce: ${data.nonce} Valid: ${data.valid}` || "No nonce received");
            setRunning(false);
        } else
            setMessage(res.statusText);
    }

    return (
        <div>
            <button
                onClick={handleClick}
                disabled={running}
                className="px-6 py-3 rounded-xl bg-blue-600 text-white disabled:opacity-50"
            >
                {running ? "Running..." : "Start SSA"}
            </button>
            <p>{message}</p>
        </div>
    )
}

Secure your API endpoint with a Rate Limiter

'use server'
import {NextResponse} from "next/server";
import {nonceManager} from "@/[wherever you store your nonceManager instance]";
import {RateLimitResult} from "@tozielinski/next-upstash-nonce";

export async function POST(req: Request) {
    const rateLimiter: RateLimitResult = await nonceManager.rateLimiter(req!);

    // result will be {valid: true, ip: string, requests: number} or
    // {valid false, ip:string, requests: number, reason: string, response: NextResponse}
    // if rate limit was reached or broken:
    //
    // export type RateLimitResult = | {
    //     valid: true;
    //     ip: string;
    //     requests: number;
    // } | {
    //     valid: false;
    //     ip: string;
    //     requests: number;
    //     reason: `too-many-requests: ${number}`;
    //     response: Response;
    // };

    return NextResponse.json({valid: result.valid, ip: result.ip, requests: result.requests});
}