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

@hotosm/hanko-auth

v0.4.4

Published

Web component for HOTOSM SSO authentication with Hanko and OSM integration

Downloads

1,586

Readme

Web Component: <hotosm-auth>

Lit-based web component for HOTOSM SSO authentication with Hanko and OpenStreetMap integration.

Installation

# npm
npm install @hotosm/hanko-auth

# pnpm
pnpm add @hotosm/hanko-auth

# yarn
yarn add @hotosm/hanko-auth

Quick Start

Import the component

import "@hotosm/hanko-auth";

Use in HTML

<hotosm-auth
  hanko-url="https://login.hotosm.org"
  show-profile="true"
></hotosm-auth>

React Example

import { useEffect, useRef } from "react";
import "@hotosm/hanko-auth";

export function AuthButton({ hankoUrl, onLogin }) {
  const ref = useRef<HTMLElement>(null);

  useEffect(() => {
    const el = ref.current;
    const handler = (e: CustomEvent) => onLogin(e.detail.user);
    el?.addEventListener("hanko-login", handler);
    return () => el?.removeEventListener("hanko-login", handler);
  }, [onLogin]);

  return <hotosm-auth ref={ref} hanko-url={hankoUrl} osm-required />;
}

Attributes

Core

| Attribute | Type | Default | Description | | ----------- | ------ | ------------------------ | ------------------------------------------ | | hanko-url | string | window.location.origin | Login service URL for Hanko authentication | | base-path | string | "" | Base URL for OSM OAuth endpoints | | auth-path | string | /api/auth/osm | OSM auth endpoints path |

Behavior

| Attribute | Type | Default | Description | | ---------------- | ------- | -------------- | -------------------------- | | osm-required | boolean | false | Require OSM connection | | osm-scopes | string | "read_prefs" | Space-separated OSM scopes | | auto-connect | boolean | false | Auto-redirect to OSM OAuth | | verify-session | boolean | false | Verify session on return |

Display

| Attribute | Type | Default | Description | | ---------------- | ------- | ---------- | ----------------------------------------------------------------- | | show-profile | boolean | false | Show full profile (vs header button) | | display-name | string | "" | Override display name | | lang | string | "en" | Language/locale code (e.g., "en", "es", "fr"). Enlish as fallback | | button-variant | string | "filled" | Button style: filled, outline, or plain | | button-color | string | "primary"| Button color: primary, neutral, or danger |

Redirects

| Attribute | Type | Default | Description | | ----------------------- | ------ | ------- | -------------------------- | | redirect-after-login | string | "" | URL after successful login | | redirect-after-logout | string | "" | URL after logout |

Cross-app

| Attribute | Type | Default | Description | | ------------------- | ------ | ------- | ----------------------------- | | mapping-check-url | string | "" | URL to check user mapping | | app-id | string | "" | App identifier for onboarding |

Events

The component dispatches the following custom events:

| Event | Detail | When | | --------------- | ---------------------- | --------------------------- | | hanko-login | { user: HankoUser } | User logged in | | osm-connected | { osmData: OSMData } | OSM account linked | | osm-skipped | {} | User skipped OSM connection | | auth-complete | {} | Auth flow complete | | logout | {} | User logged out |

Event Handling Example

const auth = document.querySelector("hotosm-auth");

auth.addEventListener("hanko-login", (e) => {
  console.log("Logged in:", e.detail.user.email);
});

auth.addEventListener("osm-connected", (e) => {
  console.log("OSM connected:", e.detail.osmData.osm_username);
});

auth.addEventListener("logout", () => {
  console.log("User logged out");
  window.location.href = "/";
});

Usage Modes

Header Mode (default)

Shows a compact login button in the header:

<header>
  <hotosm-auth
    hanko-url="https://login.hotosm.org"
    redirect-after-login="/"
  ></hotosm-auth>
</header>

Button Styling

Customize the login button appearance with button-variant and button-color:

<!-- Filled primary button (default) -->
<hotosm-auth hanko-url="https://login.hotosm.org"></hotosm-auth>

<!-- Outline button -->
<hotosm-auth
  hanko-url="https://login.hotosm.org"
  button-variant="outline"
  button-color="primary"
></hotosm-auth>

<!-- Plain text button -->
<hotosm-auth
  hanko-url="https://login.hotosm.org"
  button-variant="plain"
  button-color="neutral"
></hotosm-auth>

<!-- Filled danger button -->
<hotosm-auth
  hanko-url="https://login.hotosm.org"
  button-variant="filled"
  button-color="danger"
></hotosm-auth>

Profile Mode

Shows full authentication form (for login pages):

<hotosm-auth
  hanko-url="https://login.hotosm.org"
  show-profile
  osm-required
  auto-connect
  redirect-after-login="https://portal.hotosm.org"
></hotosm-auth>

Styling

The component uses Shadow DOM and can be customized using CSS custom properties.

CSS Custom Properties

| Property | Description | Default | | ----------------------------- | ---------------------------------- | ------------------------------------ | | --login-btn-margin | Margin around the login button | 0 | | --login-btn-padding | Padding inside the login button | var(--hot-spacing-x-small) var(--hot-spacing-medium) | | --login-btn-bg-color | Background color of login button | var(--hot-color-primary-1000) | | --login-btn-hover-bg-color | Background color on hover | var(--hot-color-primary-900) | | --login-btn-border-radius | Border radius of login button | var(--hot-border-radius-medium) | | --login-btn-text-color | Text color of login button | white | | --login-btn-text-size | Font size of login button text | var(--hot-font-size-medium) | | --login-btn-font-family | Font family of login button | inherit |

Example:

hotosm-auth {
  --login-btn-margin: 8px;
  --login-btn-padding: 12px 24px;
  --login-btn-bg-color: #d73f3f;
  --login-btn-hover-bg-color: #b83333;
  --login-btn-border-radius: 8px;
  --login-btn-text-color: #ffffff;
  --login-btn-text-size: 16px;
  --login-btn-font-family: 'Arial', sans-serif;
}

Configuration

Hanko URL Detection

The component detects the Hanko URL in the following priority order:

  1. hanko-url attribute
  2. <meta name="hanko-url" content="..."> tag
  3. window.HANKO_URL global variable
  4. window.location.origin (fallback)
<!-- Option 1: Attribute -->
<hotosm-auth hanko-url="https://login.hotosm.org"></hotosm-auth>

<!-- Option 2: Meta tag -->
<meta name="hanko-url" content="https://login.hotosm.org" />
<hotosm-auth></hotosm-auth>

<!-- Option 3: JavaScript -->
<script>
  window.HANKO_URL = "https://login.hotosm.org";
</script>
<hotosm-auth></hotosm-auth>