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

@authcore/core-web

v0.8.0

Published

Web Agnostic Authentication core for AuthCore

Readme

@authcore/core-web

Framework-agnostic web authentication service. Works in any browser environment with any backend.

Install

npm install @authcore/core-web @authcore/types

Why this package?

@authcore/core-web provides a lightweight client-side auth service that talks to your backend over HTTP. It has zero runtime dependencies (uses native fetch) and works with any frontend framework or vanilla JS.

If you're using React, use @authcore/react instead — it wraps this package with hooks and context.

Usage

import { AuthWebService } from '@authcore/core-web'

const auth = new AuthWebService({
  baseUrl: 'http://localhost:3000/auth',
  mode: 'api',
  persistSession: true,
  storageKey: 'authcore_token',
  user: null,
  token: '',
  isAuthenticated: false,
  isLoading: false,
  error: null,
})

// Sign in
const { user, token } = await auth.signIn({ email: '[email protected]', password: 'password' })

// Check state
console.log(auth.getState().isAuthenticated) // true
console.log(auth.getState().user)            // { id, email, role, ... }

// Subscribe to state changes
const unsubscribe = auth.subscribe(() => {
  console.log('State changed:', auth.getState())
})

// Sign out
await auth.signOut()

Custom Backend Integration

AuthWebService works with any backend. Use the third constructor argument to adapt response shapes, error formats, or replace the HTTP client entirely.

Different response shapes

// Backend returns: { data: { user }, access_token: "..." }
const auth = new AuthWebService(initialState, routes, {
  transformers: {
    transformAuthResponse: (raw) => {
      const r = raw as { data: { user: MyUser }; access_token: string }
      return { user: r.data.user, token: r.access_token }
    },
    transformUser: (raw) => (raw as { data: MyUser }).data,
  },
})

Different error shapes

// Backend returns: { message: "Unauthorized" }
const auth = new AuthWebService(initialState, routes, {
  transformers: {
    transformError: (body, status) => {
      const err = body as { message?: string }
      return err.message ?? `Request failed with status ${status}`
    },
  },
})

Custom HTTP client

import axios from 'axios'

const auth = new AuthWebService(initialState, routes, {
  httpClient: {
    get: <T>(path: string) =>
      axios.get<T>(`https://api.example.com${path}`).then(r => r.data),
    post: <T>(path: string, body?: unknown) =>
      axios.post<T>(`https://api.example.com${path}`, body).then(r => r.data),
  },
})

Extended user type

Pass a type parameter to get typed access to extra fields on the user object:

interface MyUser extends PublicUser {
  avatarUrl: string
}

const auth = new AuthWebService<MyUser>(initialState, routes, {
  transformers: {
    transformUser: (raw) => raw as MyUser,
  },
})

auth.getState().user?.avatarUrl // typed

API

new AuthWebService<TUser>(initialState, routes?, options?)

Creates an auth service instance.

initialState (AuthWebStateInterface):

| Field | Type | Description | |-------|------|-------------| | baseUrl | string | Your backend URL | | mode | 'api' \| 'cookie' | 'api' uses Bearer tokens, 'cookie' uses httpOnly cookies | | persistSession | boolean | Save token in localStorage (api mode) | | storageKey | string | localStorage key for the token | | user | TUser \| null | Initial user (usually null) | | token | string \| null | Initial token (usually '') | | isAuthenticated | boolean | Initial auth state (usually false) | | isLoading | boolean | Initial loading state | | error | string \| null | Initial error state (usually null) |

routes (AuthWebRoutesInterface, optional) — override default endpoint paths:

| Field | Default | |-------|---------| | register | /register | | login | /login | | logout | /logout | | me | /me | | verifyEmail | /verify-email | | forgotPassword | /forgot-password | | resetPassword | /reset-password | | invite | /invite | | acceptInvitation | /accept-invitation |

options (optional):

| Field | Type | Description | |-------|------|-------------| | transformers.transformAuthResponse | (raw: unknown) => { user: TUser, token? } | Map sign-in/sign-up/accept-invitation response | | transformers.transformUser | (raw: unknown) => TUser | Map /me response | | transformers.transformError | (body: unknown, status: number) => string | Map error body to message string | | httpClient | { get, post } | Replace the built-in fetch client entirely |

Methods

| Method | Returns | Description | |--------|---------|-------------| | signIn({ email, password }) | Promise<AuthResponse<TUser>> | Sign in and update state | | signUp({ email, password }) | Promise<AuthResponse<TUser>> | Register and update state | | signOut() | Promise<void> | Sign out and clear state | | verifyEmail(token) | Promise<void> | Verify email with token | | forgotPassword(email) | Promise<void> | Request password reset | | resetPassword(token, password) | Promise<void> | Reset password with token | | invite(email, role?) | Promise<void> | Send an invitation | | acceptInvitation(token, password) | Promise<AuthResponse<TUser>> | Accept invitation and register | | refreshUser() | Promise<void> | Fetch current user from /me | | getState() | AuthWebStateInterface<TUser> | Get current state snapshot | | subscribe(listener) | () => void | Subscribe to state changes, returns unsubscribe |

AuthResponse<TUser>

interface AuthResponse<TUser extends PublicUser = PublicUser> {
  user: TUser
  token?: string
}

AuthRequestError

Thrown when the backend returns a non-2xx response.

class AuthRequestError extends Error {
  code: string | undefined  // optional machine-readable code from the backend
  statusCode: number
}

License

MIT