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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@scratch-auth/nextjs

v0.0.1-beta.9

Published

Scratch Auth is a simple OAuth service for Scratch. It provides developers with an easy-to-understand API and users with a smooth login experience. By using @scratch-auth/nextjs, you can easily implement OAuth functionality into your site.

Downloads

500

Readme

Scratch Auth with Next.js

Scratch Auth is a simple OAuth service for Scratch. It provides developers with an easy-to-understand API and users with a smooth login experience. By using @scratch-auth/nextjs, you can easily implement OAuth functionality into your site.

Install

Scratch Auth is composed of a set of NPM packages.

npm install @scratch-auth/nextjs

Set your environment variables

Add the following keys to your file. These keys can be generated at any time using openssl rand -hex 32.

openssl rand -hex 32
SCRATCH_AUTH_SECRET_KEY=***************************************

Adding a Session Verification Page

This page will decode the session and verify account information. You need to add this file to the path of the redirect_url that you set in scratch-auth.config.ts. During the redirect, the session will be set in the privateCode parameter.

"use client";

import React, { useEffect } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { setScratchAuthSession } from "@scratch-auth/nextjs";

export default function AuthPage() {
  const router = useRouter();
  const searchParams = useSearchParams();
  const privateCode = searchParams.get("privateCode");

  useEffect(() => {
    async function auth() {
      console.log(privateCode);
      const check = await setScratchAuthSession(privateCode);
      console.log("check", check);
      if (check) {
        console.log("Authentication successful");
      } else {
        console.error("Authentication failed");
      }
      router.push("/");
    }
    auth();
  }, [privateCode]);

  return (
    <div className="flex justify-center items-center w-full h-full min-h-[calc(100dvh-64px)]">
      Authenticating Scratch account...
    </div>
  );
}

Adding an Authentication Button

By using Scratch Auth’s pre-built components, you can control the content displayed for logged-in and logged-out users. First, create a header for users to log in or out. To do this, use the following:

  • <LogIned>: The children of this component are displayed only when the user is logged in.
  • <LogOuted>: The children of this component are displayed only when the user is logged out.
  • <UserButton />: A pre-built component with styles ready to display the avatar of the logged-in user’s account.
  • <LogInButton />: An unstyled component that links to the login page. In this example, since no properties or environment variables are specified for the login URL, the component will link to the login page of the account portal.
import React from "react";
import {
  LogInButton,
  LogIned,
  LogOuted,
  UserButton,
} from "@scratch-auth/nextjs";

export default function Page() {
  return (
    <div>
      <LogOuted>
        <LogInButton />
      </LogOuted>
      <LogIned>
        <UserButton />
      </LogIned>
    </div>
  );
}

Adding the Package Configuration File

| Item | Description | | ------------ | ------------------------------------------- | | COOKIE_NAME | The name to be stored in the cookie | | redirect_url | The URL for the session authentication page | | title | Project title | | expiration | Session expiration time | | cn | CN function | | debug | Debug mode |

import { ScratchAuthConfig } from "@scratch-auth/nextjs/src/types";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

const config: ScratchAuthConfig = {
  COOKIE_NAME: "scratch-auth-session",
  redirect_url: `http://localhost:3000/api/auth`,
  title: `Scratch Auth`,
  expiration: 30,
  cn: function cn(...inputs: ClassValue[]) {
    return twMerge(clsx(inputs));
  },
  debug: true,
};

export default config;

Authenticating the Scratch Account

Run your project with the following command:

npm run dev

Access the app’s homepage at http://localhost:3000 ↗. Sign up and create the first user.