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

@phila/sso-nuxt

v0.0.4

Published

Nuxt 3 module for Azure AD B2C authentication. Installs Pinia, registers a client plugin, auto-imports `useAuth` and `useSSOStore`, and optionally guards all routes.

Downloads

279

Readme

@phila/sso-nuxt

Nuxt 3 module for Azure AD B2C authentication. Installs Pinia, registers a client plugin, auto-imports useAuth and useSSOStore, and optionally guards all routes.

Installation

pnpm add @phila/sso-nuxt @phila/sso-core @phila/sso-vue @azure/msal-browser

Setup

Add the module to your nuxt.config.ts:

export default defineNuxtConfig({
  modules: ["@phila/sso-nuxt"],

  sso: {
    globalAuth: true,
    loginPath: "/login",
    excludePaths: ["/logout"],
  },
});

Module Options

| Option | Type | Default | Description | | --------------------- | ---------- | ------------------------- | ----------------------------------------------------------------------- | | globalAuth | boolean | true | Register a global route middleware that redirects unauthenticated users | | loginPath | string | "/login" | Path to redirect unauthenticated users to | | excludePaths | string[] | ["/logout"] | Paths that bypass the auth middleware (matched with startsWith) | | signInPolicy | string | "B2C_1A_AD_SIGNIN_ONLY" | B2C sign-in user flow | | resetPasswordPolicy | string | "B2C_1A_PASSWORDRESET" | B2C password reset user flow |

Runtime Configuration

The module exposes all SSO settings via Nuxt runtime config. Set them in nuxt.config.ts or override with environment variables:

| Runtime Config Key | Environment Variable | Default | | ------------------------ | --------------------------------------- | ---------------------------- | | ssoClientId | NUXT_PUBLIC_SSO_CLIENT_ID | "" | | ssoRedirectUri | NUXT_PUBLIC_SSO_REDIRECT_URI | "http://localhost:3000" | | ssoTenant | NUXT_PUBLIC_SSO_TENANT | "PhilaB2CDev" | | ssoAuthorityDomain | NUXT_PUBLIC_SSO_AUTHORITY_DOMAIN | "PhilaB2CDev.b2clogin.com" | | ssoApiScope | NUXT_PUBLIC_SSO_API_SCOPE | "" | | ssoSignInPolicy | NUXT_PUBLIC_SSO_SIGN_IN_POLICY | from module options | | ssoResetPasswordPolicy | NUXT_PUBLIC_SSO_RESET_PASSWORD_POLICY | from module options | | ssoLoginPath | NUXT_PUBLIC_SSO_LOGIN_PATH | from module options | | ssoExcludePaths | NUXT_PUBLIC_SSO_EXCLUDE_PATHS | from module options |

Example .env:

NUXT_PUBLIC_SSO_CLIENT_ID=your-client-id
NUXT_PUBLIC_SSO_TENANT=YourTenant
NUXT_PUBLIC_SSO_AUTHORITY_DOMAIN=YourTenant.b2clogin.com
NUXT_PUBLIC_SSO_REDIRECT_URI=http://localhost:3000
NUXT_PUBLIC_SSO_API_SCOPE=https://YourTenant.onmicrosoft.com/api/read

API Scopes

ssoApiScope accepts a comma-separated string. The module splits it into an array at runtime:

NUXT_PUBLIC_SSO_API_SCOPE=https://tenant.onmicrosoft.com/api/read,https://tenant.onmicrosoft.com/api/write

Auto-Imports

The module auto-imports these composables globally:

  • useAuth() — primary auth composable (state, actions, utilities)
  • useSSOStore() — direct Pinia store access

No import statements needed in your components:

<script setup>
const { isAuthenticated, userName, authReady, signIn, signOut } = useAuth();
</script>

<template>
  <div v-if="!authReady">Loading...</div>
  <div v-else-if="isAuthenticated">
    <p>Welcome, {{ userName }}</p>
    <button @click="signOut()">Sign out</button>
  </div>
  <div v-else>
    <button @click="signIn()">Sign in</button>
  </div>
</template>

Route Middleware

When globalAuth: true (default), the module registers a global route middleware that:

  1. Waits for auth initialization (authReady) before making decisions
  2. Allows navigation to loginPath and all excludePaths
  3. Redirects unauthenticated users to loginPath

Excluding Paths

Paths in excludePaths are matched using startsWith, so /public also matches /public/about:

export default defineNuxtConfig({
  sso: {
    excludePaths: ["/logout", "/public", "/callback"],
  },
});

The loginPath is always excluded automatically.

Disabling the Middleware

Set globalAuth: false to disable the global middleware and handle auth checks manually:

export default defineNuxtConfig({
  sso: {
    globalAuth: false,
  },
});

What the Module Does

During setup, the module automatically:

  1. Installs @pinia/nuxt (apps don't need to add it separately)
  2. Adds @phila/sso-core and @phila/sso-vue to the Vite transpile list
  3. Configures Vite dev server to serve files from the monorepo root
  4. Declares all SSO keys in runtimeConfig.public
  5. Registers a client-only plugin that initializes the B2C auth client
  6. Auto-imports useAuth and useSSOStore
  7. Registers the global auth route middleware (when globalAuth: true)

License

MIT