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

persian-auth

v0.1.1

Published

Persian (Farsi) authentication React components: phone + OTP, username/password, email, and GitHub OAuth.

Downloads

12

Readme

persian-auth

Persian (Farsi) authentication React components — without React Query.

Phone + OTP, username/password, email, and GitHub OAuth. RTL-ready, fully typed, framework-agnostic.

npm version types license bundle


Highlights

  • Drop-in Persian login UI for phone + OTP, username/password, email/password, and GitHub OAuth.
  • Ships ESM + CJS with full type definitions.
  • Works in any React 18/19 app — Next.js, Vite, Remix, CRA, etc.
  • No React Query, no global cache, no extra setup — just render a component.
  • All Persian copy is built in. Validation powered by zod.
  • Pure callbacks: success and error are surfaced as typed handlers.

Why no React Query?

persian-auth is designed for authentication flows, not general server-state caching.

Most auth screens only need a small set of async actions:

  • request an OTP
  • verify an OTP
  • submit username/password or email/password credentials
  • start an OAuth redirect
  • receive a typed success or error result

This library owns those auth-specific loading and error states for you. You don't need to wrap login screens in useMutation, configure a QueryClient, or pull in a server-state cache just to build a login page.

If you already use React Query in your app, that's fine — persian-auth doesn't fight it. It just doesn't require it.


Auth Actions, in one sentence

An auth action is a focused async operation used by an authentication UI — request OTP, verify OTP, submit credentials, start OAuth, log out.

Unlike a data-fetching library, persian-auth intentionally does not manage query keys, cache invalidation, stale times, pagination, or background refetching. It only handles the state needed for authentication flows.


Table of contents


Install

npm install persian-auth zod
# or
pnpm add persian-auth zod
# or
yarn add persian-auth zod

react and react-dom are peer dependencies (>= 18).


Quick start

import {
  PersianLoginLibrary,
  GithubLoginButton,
  type AuthSuccessData,
} from "persian-auth";
import "persian-auth/styles.css"; // optional default styling

export function LoginPage() {
  const onAuthSuccess = (data: AuthSuccessData) => {
    console.log("logged in:", data);
  };
  const onAuthError = (err: string) => console.error(err);

  return (
    <>
      <PersianLoginLibrary
        type="phone"
        onAuthSuccess={onAuthSuccess}
        onAuthError={onAuthError}
      />
      <PersianLoginLibrary
        type="email"
        onAuthSuccess={onAuthSuccess}
        onAuthError={onAuthError}
      />
      <PersianLoginLibrary
        type="username"
        mode="signup"
        onAuthSuccess={onAuthSuccess}
        onAuthError={onAuthError}
      />
      <GithubLoginButton
        clientId={process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID!}
        redirectUri="https://example.com/login"
        onAuthSuccess={onAuthSuccess}
        onError={onAuthError}
      />
    </>
  );
}

Wrap your app in an RTL container so layout renders correctly:

<html lang="fa" dir="rtl">
  …
</html>

Wiring up a real backend

By default the form simulates API calls with an 800 ms delay. Pass your own async functions to talk to a real backend — no useMutation needed, the library tracks loading and errors for you:

<PersianLoginForm
  type="phone"
  onAuthSuccess={onAuthSuccess}
  onError={onAuthError}
  requestOtp={async (phoneNumber) => {
    await fetch("/api/otp/request", {
      method: "POST",
      body: JSON.stringify({ phoneNumber }),
    });
  }}
  verifyOtp={async (phoneNumber, code) => {
    const res = await fetch("/api/otp/verify", {
      method: "POST",
      body: JSON.stringify({ phoneNumber, code }),
    });
    if (!res.ok) throw new Error("کد تأیید اشتباه است");
  }}
  submitCredentials={async ({ username, email, password }, mode) => {
    const res = await fetch(`/api/auth/${mode}`, {
      method: "POST",
      body: JSON.stringify({ username, email, password }),
    });
    if (!res.ok) throw new Error("خطا در احراز هویت");
  }}
/>

Anything thrown becomes a typed error in onError. Anything resolved triggers onAuthSuccess with a typed payload.


GitHub OAuth

GithubLoginButton performs the redirect half of the standard authorization-code flow:

  1. On click, it redirects the browser to https://github.com/login/oauth/authorize with client_id, redirect_uri, scope, and a CSRF state (persisted in sessionStorage).
  2. GitHub redirects back to your redirectUri with ?code=…&state=….
  3. The button, when rendered on that return page, reads the code, validates state, and calls onAuthSuccess({ type: "github", provider: "github", githubCode }).
  4. Your server must exchange the code for a token — this requires the client secret and cannot be done in the browser.

Typical server-side exchange:

// Next.js Route Handler example: app/api/github/callback/route.ts
const res = await fetch("https://github.com/login/oauth/access_token", {
  method: "POST",
  headers: { Accept: "application/json", "Content-Type": "application/json" },
  body: JSON.stringify({
    client_id: process.env.GITHUB_CLIENT_ID,
    client_secret: process.env.GITHUB_CLIENT_SECRET,
    code,
    redirect_uri: process.env.GITHUB_REDIRECT_URI,
  }),
});

Public API

| Export | Kind | Purpose | | --------------------------------------------- | --------- | ---------------------------------------------------------------------------------- | | PersianLoginLibrary | component | High-level wrapper with onAuthSuccess / onAuthError. | | PersianLoginForm | component | Lower-level form. Accepts custom requestOtp / verifyOtp / submitCredentials. | | GithubLoginButton | component | OAuth kick-off + automatic callback handler. | | usePersianLoginForm | hook | Headless form state and handlers for custom UI. | | LoginType, FormMode, AuthSuccessData, … | types | See src/types.ts. |


Repository layout

src/                 # library source (shipped)
  index.ts           # public API
  components/        # PersianLoginForm, PersianLoginLibrary, GithubLoginButton
  hooks/             # usePersianLoginForm
  types.ts           # shared public types
  styles.css         # optional default styling (opt-in)
app/                 # Next.js demo / showcase (not shipped)
dist/                # build output (git-ignored)

Scripts

npm run dev         # start the Next.js demo at http://localhost:3000
npm run build       # production build of the demo app
npm run typecheck   # tsc --noEmit across the whole repo
npm run build:lib   # bundle src/ into dist/ (ESM + CJS + .d.ts) via tsup

License

MIT