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

tutoruu-auth

v1.0.3

Published

React sdk for authenticating tutoruu users

Readme

Tutoruu Auth SDK

Installation

npm i tutoruu-auth #npm
yarn add tutoruu-auth #yarn
pnpm add tutoruu-auth #pnpm

Usage

Basic Setup

Set up API handler in pages/api/auth.ts:

// /pages/api/auth.ts
import { createAuthAPIHandler } from 'tutoruu-auth';

export default createAuthAPIHandler();

Set up AuthContext in _app.tsx:

// /pages/_app.tsx
import { AuthContext } from 'tutoruu-auth';

export default function App({ Component, pageProps }) {
  return (
    <AuthContext>
      <Component {...pageProps} />
    </AuthContext>
  );
}

Add auth screen in pages/auth.tsx:

// /pages/auth.tsx
import { useAuth } from 'tutoruu-auth';
import { useEffect } from 'react';

export default function Auth() {
  const { protect } = useAuth();

  useEffect(() => {
    protect(() => {
      window.location.replace(
        window.location.href.split('?')[1]?.split('=')[1] ?? '/'
      );
    });
  }, []);
}

Page Protection

You can use the createSSRAuthentication Helper to protect pages from being accessed by unauthenticated users. If a user is not authenticated, they will be redirected to the login page, and then back to the page they were trying to access.

import { createSSRAuthentication } from 'tutoruu-auth';

export const getServerSideProps = createSSRAuthentication();

// or with callback

export const getServerSideProps = createSSRAuthentication((ctx) => {
  // do something
  console.log('will log in before reaching this code');
});

The useAuth Hook

import { useAuth } from 'tutoruu-auth';

export const Component: FC = () => {
  const { protect, redirect, session } = useAuth();

  const login = () => {
    protect(() => {
      // do something
      console.log('will log in before reaching this code');
      redirect('/dashboard'); // redirect with token appended to url
    });
  };

  if (session?.user) return <div>User is {session.user.name}</div>;
  else return <button onClick={login}>Log in</button>;
};

The UserButton Component

Shows a button that logs in the user if they are not logged in, and shows their image if they are logged in.

import { UserButton } from 'tutoruu-auth';

const Navbar: FC = () => {
  return (
    <div>
      <UserButton />
    </div>
  );
};

Authenticating routes

You can use the createAuthenticatedRoute helper to protect endpoints from being accessed by unauthenticated users.

import { createAuthenticatedRoute } from 'tutoruu-auth'

export const handler = createAuthenticatedRoute({
    onAuthenticated: async (req, res) => {
        // do something
        console.log("will log in before reaching this code");
    },
    onLoggedOut: async (req, res) => {
        // do something
        console.log("If the user is not logged in, this code will run");
    }
);