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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@al-hamoud/authx

v1.4.5

Published

Auth toolkit: Firebase JWKS verify + Supabase user ensure for Next.js Edge runtime

Readme

@al-hamoud/authx

Auth toolkit for Firebase Supabase in Edge environments (Next.js friendly).

  • Verify Firebase ID tokens using Google JWKS (JOSE)
  • Ensure a Supabase user exists (service role admin) and tag roles/metadata
  • Drop-in Next.js Edge route handler

Install

npm install @al-hamoud/authx

(This package bundles jose and @supabase/supabase-js as dependencies.)

Quick start

Verify a Firebase ID token

import { verifyFirebaseIdToken } from '@al-hamoud/authx'

const projectId = process.env.FIREBASE_PROJECT_ID!
const payload = await verifyFirebaseIdToken(idToken, projectId)

console.log(payload.sub, payload.phone_number, payload.email)

Ensure a Supabase user exists

import { makeAdminClient, ensureSupabaseUser } from '@al-hamoud/authx'

const admin = makeAdminClient({
  url: process.env.SUPABASE_URL!,
  serviceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY!,
})

const user = await ensureSupabaseUser(admin, payload)
console.log('Supabase user id:', user.id)

Next.js Edge route (drop-in)

// app/api/auth/verify-id-token/route.ts
export const runtime = 'edge'

import { buildVerifyRouteHandler } from '@al-hamoud/authx'

const handler = buildVerifyRouteHandler({
  projectId: process.env.FIREBASE_PROJECT_ID!,
  supabaseUrl: process.env.SUPABASE_URL!,
  supabaseServiceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY!,
})

export async function POST(req: Request) {
  return handler(req)
}

Request contract:

  • Method: POST
  • Body: { idToken: string }

Response (200):

{
  "ok": true,
  "uid": "...",
  "phoneNumber": "+44...",
  "email": null,
  "supabaseUserId": "...",
  "note": "Verified Firebase token and ensured Supabase user exists."
}

Environment variables

  • FIREBASE_PROJECT_ID (server)
  • SUPABASE_URL (server)
  • SUPABASE_SERVICE_ROLE_KEY (server; keep secret)

Client Firebase config (NEXT_PUBLIC_...) is handled by your app’s Firebase SDK; this library validates server-side.

Types

import type { FirebaseIdTokenPayload } from '@al-hamoud/authx'

UI Component

The package also includes a React component for phone authentication:

import { Authx } from '@al-hamoud/authx'

<Authx 
  verifyEndpoint="/api/auth/verify-id-token"
  initialCountry="GB"
/>

Custom Countries Configuration

You can customize the available countries in the phone number picker:

import { Authx, COUNTRIES } from '@al-hamoud/authx'

// Use only specific countries (v1.2.1+)
const customCountries = {
  GB: COUNTRIES.GB,
  US: COUNTRIES.US,
}

<Authx countries={customCountries} />
// Add your own custom countries
const extendedCountries = {
  ...COUNTRIES,
  CA: { name: 'Canada', dial: '+1', flag: '🇨🇦', min: 10, max: 10 },
  AU: { name: 'Australia', dial: '+61', flag: '🇦🇺', min: 9, max: 9 },
}

<Authx countries={extendedCountries} />

New in v1.2.1:

  • Flexible Types: No TypeScript errors when using partial country lists
  • Auto-fallback: Gracefully handles missing countries with fallback to defaults
  • Better DX: No type assertions needed

Available countries by default:

  • 🇬🇧 GB: United Kingdom (+44)
  • 🇺🇸 US: United States (+1)
  • 🇦🇪 AE: UAE (+971)
  • 🇸🇦 SA: Saudi Arabia (+966)
  • 🇩🇪 DE: Germany (+49)
  • 🇫🇷 FR: France (+33)

Security notes

  • JWKS validation enforces issuer and audience:
    • issuer: https://securetoken.google.com/${projectId}
    • audience: projectId
  • Keep the Supabase service role key server-side only.
  • Consider origin checks and rate limiting on the verify route.

Made for Next.js Edge. Works in standard Node runtimes as well.