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

@ministerjs/auth

v1.0.2

Published

Classe para gerenciar autenticação de usuários em aplicações Vue.

Readme

@ministerjs/auth

Classe para gerenciar autenticação de usuários em aplicações Vue.

Instalação

pnpm add @ministerjs/auth

Importação

import { Auth } from "@ministerjs/auth/Auth";

Exemplo de Uso

import { Auth } from "@ministerjs/auth/Auth";

const auth = new Auth({
  fetch: window.fetch.bind(window),
  mapUser: (user) => {
    // Transformar ou filtrar dados do usuário antes de salvar
    return {
      ...user,
      fullName: `${user.firstName} ${user.lastName}`,
    };
  },
  routes: {
    login: "/api/login",
    checkIn: "/api/checkin",
    logout: "/api/logout",
  },
  afterLogout: () => {
    // Ações após fazer logout
    console.log("Usuário deslogado!");
  },
  afterCheckIn: (result) => {
    // Ações após verificação do estado de login
    console.log("CheckIn foi bem-sucedido?", result);
  },
});

Atributos Importantes

  • auth.user: contém os dados do usuário autenticado (ou null se não autenticado).
  • auth.on: booleano que indica se o usuário está logado (true/false).
  • auth.loading: booleano que indica se há uma operação de login, checkIn ou logout em andamento.
  • auth.checkedIn: booleano que indica se o checkIn() já foi executado.

Métodos

login(payload: Record<string, any>)

  • Faz a chamada de login para a rota configurada em routes.login.
  • Ao receber resposta:
    • Define auth.on como true.
    • Armazena o usuário em auth.user.
    • Define auth.loading como false.

Exemplo:

await auth.login({ username: "john", password: "1234" });
console.log(auth.user.value); // Dados do usuário logado

checkIn()

  • Verifica se o usuário já está autenticado (ex.: mantém a sessão em abas novas).
  • Atualiza auth.user e auth.on conforme o resultado.
  • Chama o callback afterCheckIn(true|false) dependendo do sucesso ou falha na verificação.
  • Atualiza auth.checkedIn para true quando finaliza.

Exemplo:

await auth.checkIn();
console.log(auth.on.value);         // true ou false
console.log(auth.checkedIn.value);  // true

logout()

  • Faz a chamada de logout para a rota configurada em routes.logout.
  • Define auth.on como false, limpa auth.user e chama afterLogout() após concluir.

Exemplo:

await auth.logout();
console.log(auth.on.value); // false
console.log(auth.user.value); // null

Opções do Construtor

  • fetch: Fetch
    Instância de Fetch responsável pelas requisições HTTP.

  • mapUser?: (user: User) => User
    Callback para ajustar dados do usuário antes de armazenar em auth.user.

  • routes?: { login?: string; checkIn?: string; logout?: string; }
    Rotas customizadas para as operações de login, checkIn e logout.

  • afterLogout?: () => void | Promise<void>
    Executado logo após o logout.

  • afterCheckIn?: (result: boolean) => void | Promise<void>
    Executado após a tentativa de checkIn, recebendo true ou false como resultado.

Rotas do Backend

Para que a classe Auth funcione corretamente, o backend deve expor as rotas (por padrão: /api/login, /api/checkin, /api/logout).

  • Login: recebe as credenciais no corpo da requisição, valida e retorna { message, data }.
  • CheckIn: verifica a sessão e retorna { message, data } se o usuário estiver autenticado, ou algum erro/status caso não esteja.
  • Logout: invalida a sessão/tokens e retorna { message }.