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

@robosophy/auth

v1.2.0

Published

Sesión de los fronts de Mi Cuenta contra el Landing: access token RS256 de 15 minutos en `localStorage["token"]`, refresh opaco en cookie HttpOnly y datos del usuario desde `GET /api/usuario/self`.

Readme

@robosophy/auth

Sesión de los fronts de Mi Cuenta contra el Landing: access token RS256 de 15 minutos en localStorage["token"], refresh opaco en cookie HttpOnly y datos del usuario desde GET /api/usuario/self.

No depende de ningún framework. Necesita axios (peer dependency) y fetch.

Instalación

npm install @robosophy/auth

Configuración

Se llama una sola vez, al arrancar la app:

import { configureAuth } from "@robosophy/auth";

configureAuth({
  landingUrl: import.meta.env.VITE_LANDING_URL, // origin del Landing (front y back comparten origin)
  isDev: import.meta.env.DEV,
});

hostsLogin: true solo en Landing, que es el que tiene el login: redirige a su propio /login (window.location.origin) y lo hace también en DEV. Los módulos no lo pasan: van a {landingUrl}/login y en DEV no redirigen.

API

| Función | Qué hace | |---|---| | configureAuth(opts) | Guarda landingUrl, isDev y hostsLogin. | | getToken() | Devuelve localStorage["token"] o null. | | attachAuthRefresh(api) | Agrega el Bearer a cada request y ante un 401 renueva el token y reintenta una vez. | | getCurrentUser() | GET {landingUrl}/api/usuario/self, cacheado en memoria. Si falla, el cache se descarta. | | setSession(token) | Guarda el token nuevo e invalida el cache del usuario. | | logout() | POST {landingUrl}/api/auth/logout, limpia la sesión y va al login (ver hostsLogin). | | clearSession() | Borra token, user-id, originalToken y token-landing de localStorage. |

Cómo se renueva el token

Ante un 401 de un request que todavía no se reintentó:

  1. Se toma el lock basf-auth-refresh con navigator.locks, compartido entre pestañas. Si el navegador no lo soporta, se deduplica solo dentro de la pestaña.
  2. Si localStorage["token"] ya cambió, otra pestaña renovó primero y se usa ese token.
  3. Si no, se pide uno nuevo: POST {landingUrl}/api/auth/refresh con credentials: "include", que rota la cookie de refresh.
  4. Con token nuevo se reintenta el request original. Si no hay token:
    • En DEV: console.warn('[auth] sin sesión: copiá el token de dev en localStorage (key "token") y recargá') y el error sigue. No redirige (salvo con hostsLogin).
    • En prod, o con hostsLogin: clearSession() y redirect al login, salvo que ya esté en esa página.

Los 401 de /api/auth/login, /api/auth/verify-2fa, /api/auth/resend-2fa, /api/auth/refresh y /api/auth/logout no disparan el refresh: ahí el 401 es la respuesta (credenciales, código 2FA, refresh vencido). El resto de /api/auth/*, como request-2fa-challenge, sí renueva y reintenta.

Uso en Vue

// main.js
import { configureAuth } from "@robosophy/auth";

configureAuth({
  landingUrl: import.meta.env.VITE_LANDING_URL,
  isDev: import.meta.env.DEV,
});
// axiosClient.js
import axios from "axios";
import { attachAuthRefresh } from "@robosophy/auth";

const api = axios.create({ baseURL: import.meta.env.VITE_URL });
attachAuthRefresh(api);
export default api;
// router/index.js
import { getCurrentUser } from "@robosophy/auth";

router.beforeEach(async (to) => {
  if (!to.meta.requiresAuth) return true;
  try {
    const user = await getCurrentUser();
    return Boolean(user?.rolCYO?.rol);
  } catch {
    return false; // attachAuthRefresh ya redirigió al login (prod) o avisó por consola (DEV)
  }
});
<!-- Botón de salir -->
<script setup>
import { logout } from "@robosophy/auth";
</script>

<template>
  <button @click="logout">Salir</button>
</template>

Uso en React

// main.tsx
import { configureAuth } from "@robosophy/auth";

configureAuth({
  landingUrl: import.meta.env.VITE_LANDING_URL,
  isDev: import.meta.env.DEV,
});
// useCurrentUser.ts
import { useEffect, useState } from "react";
import { getCurrentUser } from "@robosophy/auth";

export function useCurrentUser<T>() {
  const [user, setUser] = useState<T | null>(null);
  useEffect(() => {
    getCurrentUser<T>().then(setUser).catch(() => setUser(null));
  }, []);
  return user;
}
import { logout } from "@robosophy/auth";

<button onClick={() => logout()}>Salir</button>;

Desarrollo local

En dev el access token dura 24 h. Para trabajar con un front local: loguearse en https://dev.micuenta.basf.com.ar, copiar token del localStorage y pegarlo en el localStorage del front local (localhost:<puerto>), con la misma key. Con isDev el paquete no redirige al login: si el token vence, avisa en la consola y hay que pegar uno nuevo.