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

gov-sso-login

v1.1.0

Published

IAM-GOV SSO Login library for React/Next.js applications

Readme

gov-sso-login

IAM-GOV SSO Login library สำหรับ React/Next.js applications

Installation

npm install gov-sso-login

Quick Start

1. Config

import type { GovSsoConfig } from 'gov-sso-login';

const ssoConfig: GovSsoConfig = {
  iamAuthUrl: 'https://auth.govcenter.co',
  serviceCode: 'my-service-code',
  apiBaseUrl: 'https://api.example.com',
  callbackUrl: 'https://example.com/auth/callback',
};

2. Login Button

import { SsoLoginButton } from 'gov-sso-login';

export default function LoginPage() {
  return (
    <SsoLoginButton
      config={ssoConfig}
      label="เข้าสู่ระบบด้วย Gov Center"
    />
  );
}

3. Callback Handler

import { SsoCallbackHandler } from 'gov-sso-login';

export default function CallbackPage() {
  return (
    <SsoCallbackHandler
      config={ssoConfig}
      onSuccess={(result) => {
        console.log('Login success:', result.user);
        window.location.href = '/dashboard';
      }}
      onError={(err) => {
        console.error('Login failed:', err.message);
        window.location.href = '/login';
      }}
    />
  );
}

4. Using Hooks (Custom UI)

import { useGovSso, useGovSsoCallback } from 'gov-sso-login';

// Login hook
function LoginPage() {
  const { login, getLoginUrl } = useGovSso(ssoConfig);
  return <button onClick={login}>Login</button>;
}

// Callback hook
function CallbackPage() {
  const { status, user, error, message } = useGovSsoCallback(ssoConfig, {
    onSuccess: (result) => { /* ... */ },
    onError: (err) => { /* ... */ },
  });

  if (status === 'loading') return <p>Loading...</p>;
  if (status === 'error') return <p>Error: {error?.message}</p>;
  return <p>Welcome, {user?.firstName}!</p>;
}

5. Core Client (Non-React)

import { GovSsoClient } from 'gov-sso-login';

const client = new GovSsoClient(ssoConfig);

// Get login URL
const url = client.getLoginUrl();

// Handle callback
const result = await client.handleCallback(code);

API Reference

GovSsoConfig

| Property | Type | Required | Description | |---|---|---|---| | iamAuthUrl | string | ✅ | IAM-GOV auth frontend URL | | serviceCode | string | ✅ | Service code registered with IAM-GOV | | apiBaseUrl | string | ✅ | Backend API URL | | callbackUrl | string | ✅ | Frontend callback URL | | ssoCallbackPath | string | ❌ | Backend callback path (default: /auth/sso-callback) |

Exports

  • GovSsoClient — Core client class
  • useGovSso(config) — Hook for login initiation
  • useGovSsoCallback(config, options?) — Hook for callback handling
  • SsoLoginButton — Ready-made login button component
  • SsoCallbackHandler — Ready-made callback page component

Backend Requirements

Your backend needs a POST /auth/sso-callback endpoint that:

  1. Receives { code } from the frontend
  2. Sends the code to IAM-GOV /e-services/sso/verify-code with API key
  3. Returns { success: true, user: { ... } } and sets JWT cookies

License

MIT