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

@yasser172/tec-auth

v1.1.1

Published

TEC Ecosystem — Shared Auth Layer (Pi SSO + JWT + Cookies + Middleware)

Readme

@yasser172/tec-auth

Shared authentication layer for the TEC Federated Platform. Provides Pi SSO hooks, cookie parsing, refresh/logout helpers, and Next.js middleware for all TEC apps (Hub, Ecommerce, Assets, Commerce).

SSO is cookie-based — the Hub sets HttpOnly cookies and every app reads them. This package never stores tokens in localStorage/sessionStorage (ADR-001).


Install

npm install @yasser172/tec-auth

Peer dependencies: next >=15, react >=18, react-dom >=18.


Quick start

'use client';
import { usePiAuth } from '@yasser172/tec-auth';

export function Profile() {
  const { user, token, isAuth, loading } = usePiAuth();
  if (loading) return <p>Loading…</p>;
  if (!isAuth) return <a href="/login">Sign in</a>;
  return <p>Welcome, {user?.piUsername}</p>;
}

Reading the session (anywhere)

import { getStoredUser, getAccessToken, hasValidSession } from '@yasser172/tec-auth';

const user  = getStoredUser();    // parses the tec_user cookie
const token = getAccessToken();   // tec_access_token cookie
const ok    = hasValidSession();  // both present

SSO redirect (non-Hub apps)

import { ssoRedirect } from '@yasser172/tec-auth';

// Bounces to hub.tecosystem.app/login?return_url=<current> when unauthenticated.
ssoRedirect();

Authenticated fetch + refresh

import { fetchWithAuth, refreshAccessToken, logout } from '@yasser172/tec-auth';

const res = await fetchWithAuth('/api/bff/wallet/balance'); // auto-refreshes on 401

Middleware (protected routes)

The ./middleware subpath exports Next.js middleware helpers for guarding routes and forwarding session cookies:

import { /* middleware helpers */ } from '@yasser172/tec-auth/middleware';

API

| Export | Description | |--------|-------------| | usePiAuth() | React hook → { user, token, isAuth, loading } | | getStoredUser() | Parses the tec_user cookie → TecUser \| null | | getAccessToken() / getCsrfToken() | Read auth/CSRF cookies | | hasValidSession() | true when user + access token present | | ssoRedirect() / buildSsoUrl() | Redirect to Hub login with return_url | | refreshAccessToken() / fetchWithAuth() / logout() | Token lifecycle | | isPiBrowser() / waitForPiSDK() / loginWithPi() | Pi Browser helpers (Hub) | | @yasser172/tec-auth/middleware | Next.js middleware for protected routes |

Cookie contract (LOCKED): tec_access_token, tec_csrf, tec_user.


Rules

  • HttpOnly cookies only — never localStorage (ADR-001).
  • Token verification happens in tec-auth-service, never in this package.
  • Cookie names are LOCKED — renaming requires a coordinated deploy across all apps.

Development

npm run build              # tsup → dist/ (ESM + CJS + .d.ts)
npm run test               # vitest
npx vitest run --coverage  # coverage (floor: 80%)
npm run typecheck          # tsc --noEmit

License

MIT © TEC