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

@unologin/next

v0.1.3

Published

Next.js library for interfacing with unolog·in.

Readme

Add unolog·in to your Next.js application.

The full documentation for this package can be found here.

Documentation for other packages and useful guides can be found on our documentation page.

Installation

Install via npm:

npm install @unologin/next

Install via yarn:

yarn add @unologin/next

Quick Setup

Creating a Next.js application

If you haven't already, set up a Next.js application.

Registering your application

To use unolog·in, click here to register your application.

Setting up environment variables

After registering your application, you should be given a config file like this:

UNOLOGIN_API_KEY=...
UNOLOGIN_COOKIES_DOMAIN=...
NEXT_PUBLIC_UNOLOGIN_APPID=...

Download the file and place it at the top level of your Next.js project (next to the package.json file).

Adding API request handlers

Add your API request handlers by creating a file located at pages/api/unologin/[unologin].js (or .ts) within your Next.js project.

Add the following lines of code:

import {
  nextApiHandler
} from '@unologin/next/quick';

export default nextApiHandler;

This will handle all unolog·in related event handlers for you.

Setting up the client library

Set up the client library by importing clientSetup and running in the component file you plan on using it.

import {
  clientSetup,
} from '@unologin/next/quick';

clientSetup();

Done!

Congratulations, your application now has authentication, registration, login and more.

Usage

Starting the login flow

The login flow can be initiated by calling the login function returned by calling the useLogin hook.


import {
  useLogin,
} from '@unologin/next/react';

function LoginButton()
{
  const login = useLogin();

  return <button onClick={() => login()}>
    log in
  </button>
}

This will start the login flow, but won't react in any way once it has completed.

Keep on reading to see how to tell if the user is logged in.

Checking the login state on the client

The login state can be checked on the client by calling useClientSession from any component mounted inside the ClientSessionProvider component.

IMPORTANT:

The client-side session is intended for updating the UI once the login state changes without making a request to the server.

It should not be used for authentication or authorization of any kind.


import {
  useClientSession,
  ClientSessionProvider
} from '@unologin/next/react';

const MyComponent = () => 
{
  const { isLoggedIn } = useClientSession();

  return isLoggedIn ? 
    'You are logged in :-)' :
    'You are not logged in :-(';
};

const MyApp = () => <ClientSessionProvider>
  <MyComponent />
</ClientSessionProvider>;

useLogin and useLogout

Use the useLogin and useLogout hooks to perform login and logout operations.


import {
  useLogin,
  useLogout,
  useClientSession
} from '@unologin/next/react';

function LoginButton()
{
  /**
   * login(...) may be called with or without. 
   * arguments and returns a Promise which 
   * resolves after successful login.
   * 
   * Use ```login.loading``` and ```login.open``` 
   * to determine the current state
   * of the login process 
   */
  const login = useLogin();

  return <button 
    disabled={login.loading}
    onClick={
      () => login({ userClass: 'users_default' })
    }
  >
    log in
  </button>;
}

function LogoutButton()
{
  /**
   * logout() is always called without arguments
   * and returns a Promise which resolves
   * after the user is logged out.
   * 
   * Use ```logout.loading``` to determine
   * the state of the logout operation.
   */
  const logout = useLogout();

  return <button 
    disabled={logout.loading}
    onClick={
      () => logout()
    }
  >
    log out
  </button>;
}

/**
 * Renders either login- or logout button
 * depending on the state of the ClientSessionContext.
 * 
 * Needs to be rendered inside a ClientSessionContext.
 */
function LoginLogout()
{
  const { isLoggedIn } = useClientSession();

  return isLoggedIn ?
    <LogoutButton /> :
    <LoginButton />;
}

When using our LoginLogout component, make sure it is a descendant of the ClientSessionProvider element.

It is recommended to wrap the contents of your app in ClientSessionProvider once.


import {
  ClientSessionProvider
} from '@unologin/react'

function MyApp()
{
  return <ClientSessionProvider>
    <LoginLogout />
  </ClientSessionProvider>
}

Displaying user information

To display user information, create a new component which makes use of getServerSideProps.

By wrapping getServerSideProps using withUnologin, any authentication errors are automatically handled and the context.unologin object is aware of the current request.


import {
  withUnologin
} from "@unologin/next/quick";

/**
 * Display my user info as formatted JSON.
 */
export default function MyInfo(props)
{
  return <pre>
    {JSON.stringify(props.user, null, 2)}
  </pre>;
}

export const getServerSideProps = withUnologin(
  async (context) => 
  {
    /**
     * The context object can be used
     * like the context object passed 
     * to getServerSideProps.
     * 
     * The ```unologin``` object can be used 
     * like an instance of ```UnologinNextJS```
     * but does not require ```req``` or ```res``` 
     * to be passed to any functions.
     */
    const { unologin } = context;

    return {
      props: 
      {
        /** No further parameters required. */
        user: await unologin.getUserDocument(),
      },
    };
  },
);

Advanced server-side usage

This package extends @unologin/node-sdk, specifically the class UnologinNextJs extends the HttpHandlers.

The @unologin/next/quick module will perform the required setup for you.

/**
 * With no setup required:
 */

import { 
  unologinNextJs 
} from '@unologin/next/quick' 

/** 
 * With manual setup:
 */
import UnologinNextJs 
  from '@unologin/next/server';

import unologin
  from '@unologin/node-sdk';

/**
 * You can provide your own instance of the unologin node-sdk.
 */
const unologinNextJs = new UnologinNextJs(unologin)

As a consequence, all @unologin/node-sdk-functions are available through the unologinNextJs object.

Here's an example of how to use it within an API route:


const token = unologinNextJs.getUserTokenOptional(req, res);

/** if the user is logged in */
if (token)
{
  /** Perform protected actions here. */
}

/**
 * or
 */

/** Will throw APIError if not logged in. */
const token = unologinNextJs.getUserToken(req, res);

/** Perform protected actions here. */

See the node-sdk documentation for more information.