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

@next-nest-auth/nextauth

v0.1.6

Published

NextAuth is a frontend authentication package designed for Next.js applications, providing easy integration with NestJS-based backends. It supports login, session management, and token handling (including JWT and refresh tokens) to ensure secure user auth

Readme

@next-nest-auth/nextauth

This package provides an authentication solution that integrates a NestJS backend with a Next.js frontend. It allows you to handle authentication, session management, and token refreshing in a seamless way.

Prerequisites

Before using this package, please make sure to read the documentation of @next-nest-auth/nestauth first, as it is required for the backend integration.

.env Setup

In order to use this package correctly, you need to set up the following environment variables:

BASE_URL=http://localhost:3000
API_BASE_URL=http://localhost:3001
NODE_ENV=development
  • BASE_URL: The URL of your Next.js frontend.
  • API_BASE_URL: The URL of your NestJS backend.
  • NODE_ENV: The environment mode (development, production).
  • AUTOEXPIRE_REFRESH_TOKEN: (Optional) A boolean value to determine whether to automatically expire the refresh token or not. Default is false.

Middleware Usage

You can use the checkAuth and refreshToken functions in your Next.js middleware to manage authentication and session validation for protected routes.

Example Usage:

import { NextRequest, NextResponse } from "next/server";
import { checkAuth, refreshToken } from "@next-nest-auth/nextauth";

export async function middleware(req: NextRequest) {
    const protectedRoutes = ["/dashboard", "/profile", "/settings"];

    if (
        protectedRoutes.some((route) => req.nextUrl.pathname.startsWith(route))
    ) {
        const authenticated = await checkAuth();
        if (!authenticated) {
            try {
                const response = await refreshToken(req);
                // Check other logics
                return response;
            } catch (error) {
                return NextResponse.redirect(new URL("/", req.url));
            }
        }
    }
    return NextResponse.next();
}

export const config = {
    matcher: ["/dashboard/:path*", "/profile/:path*", "/settings/:path*"],
};

Functions

authenticate

This function authenticates the user and sets the access and refresh tokens in cookies.

import { authenticate } from "@next-nest-auth/nextauth";

const response = await authenticate({
    username: "user",
    password: "password",
});

refreshToken

This function is responsible for refreshing the access token using the refresh token stored in cookies.

import { refreshToken } from "@next-nest-auth/nextauth";

const refreshedResponse = await refreshToken(req);

getUserInfo

This function retrieves the user information from the access token.

import { getUserInfo } from "@next-nest-auth/nextauth";

const userInfo = await getUserInfo();

getAccessToken / getRefreshToken

These functions retrieve the current access token and refresh token from the cookies.

import { getAccessToken, getRefreshToken } from "@next-nest-auth/nextauth";

const accessToken = await getAccessToken();
const refreshToken = await getRefreshToken();

checkAuth

This function checks if the user is authenticated by verifying the access token.

import { checkAuth } from "@next-nest-auth/nextauth";

const authenticated = await checkAuth();

logout

This function deletes the access and refresh tokens from cookies.

import { logout } from "@next-nest-auth/nextauth";

await logout();

get / post

These are helper functions to make authenticated HTTP requests using Axios.

import { get, post } from "@next-nest-auth/nextauth";

const data = await get("/some-api-endpoint");
const postData = await post("/some-api-endpoint", { someData: "value" });

License

This package is licensed under the MIT License.