
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
@plasius/auth
Advanced tools
Authentication helpers and React context components for Plasius applications.
Apache-2.0. ESM + CJS builds. TypeScript types included.
.nvmrc)peerDependencies)window/document are used)npm install @plasius/auth
import {
AuthProvider,
useAuth,
useAuthorizedFetch,
createAuthorizedFetch,
useLogin,
useLogout,
} from "@plasius/auth";
import { AuthProvider, useAuth, useLogin, useLogout } from "@plasius/auth";
import type { AuthProvider as OAuthProviderId } from "@plasius/entity-manager";
function AccountPanel() {
const { userId, validateSession } = useAuth();
const login = useLogin();
const logout = useLogout();
const provider = "github" as OAuthProviderId;
return (
<div>
<p>Signed in as: {userId ?? "anonymous"}</p>
<button onClick={() => login(provider)}>Log in</button>
<button onClick={() => logout()}>Log out</button>
<button onClick={() => validateSession()}>Revalidate session</button>
</div>
);
}
export default function App() {
return (
<AuthProvider>
<AccountPanel />
</AuthProvider>
);
}
AuthProviderProvides auth state through context and runs session validation on mount.
useAuth()Returns:
userId: string | nullsetUserId(userId: string | null)validateSession(): Promise<void>validateSession() calls GET /oauth/me and updates userId from a userId field in the response body.
useAuthorizedFetch()React hook that returns an authorized fetch wrapper.
createAuthorizedFetch()Non-hook function that creates the same authorized fetch wrapper.
Behavior:
credentials: "include".csrf-token from browser cookies and sends it as x-csrf-token when present.401, calls POST /oauth/refresh-token and retries the original request.401 so clients return failure instead of repeatedly hitting auth endpoints.429/5xx) on refresh, uses randomized logarithmic backoff with an increasing cooldown window.Retry-After (seconds) from refresh responses before retrying.useLogin()Returns a function that redirects to:
/oauth/{provider}?state={base64(currentPath)}The provider identifier type comes from @plasius/entity-manager (AuthProvider), and is separate from this package's React AuthProvider component.
useLogout()Returns a function that:
POST /oauth/logout./ regardless of request outcome.This package is frontend-only. It assumes your backend owns authentication and issues cookies.
useLogin() redirects browser to GET /oauth/{provider}?state={base64(path)}.AuthProvider calls GET /oauth/me on mount to populate userId.useAuthorizedFetch() include cookies and optional x-csrf-token.401, package sends POST /oauth/refresh-token once for concurrent callers.useLogout() sends POST /oauth/logout then redirects to /.| Route | Method | Called by | Required behavior |
|---|---|---|---|
/oauth/{provider} | GET | useLogin() | Start provider login flow; accept state query param. |
/oauth/me | GET | AuthProvider.validateSession() | Return 200 with JSON containing userId when authenticated, otherwise non-2xx (typically 401). |
/oauth/refresh-token | POST | createAuthorizedFetch() after 401 | Attempt token/session refresh using cookies; return 2xx on success, non-2xx on failure. |
/oauth/logout | POST | useLogout() | Invalidate session cookies/server session and return 2xx/204 when possible. |
GET /oauth/me success example:
{
"userId": "user_123"
}
GET /oauth/me should return 401 (or another non-2xx) when no valid session exists.
POST /oauth/refresh-token may optionally return a Retry-After response header (seconds).
If present and greater than zero, the package waits before retrying the original request.
credentials: "include" is always used).csrf-token if you want the package to send x-csrf-token.useAuthorizedFetch() adds x-csrf-token only when the csrf-token cookie exists./oauth/refresh-token do not include x-csrf-token automatically; protect this route with cookie policy and origin checks.useLogout() uses authorized fetch, so logout receives x-csrf-token when available.Configure backend CORS and cookies for credentialed requests:
Access-Control-Allow-Credentials: trueAccess-Control-Allow-Origin must be a specific origin, not *Secure and an appropriate SameSite policy for your topology./oauth/{provider} statestate is set by the client as base64(window.location.pathname). Backend should:
state as untrusted input.userId from /oauth/me for authenticated sessions.401 for expired/invalid sessions./oauth/refresh-token idempotent and safe for concurrent requests.This package is designed to align with OAuth 2.0 and current IETF security guidance when paired with a compliant backend.
state value as untrusted input.Secure, HttpOnly, SameSite aligned to deployment topology)./oauth/logout, /oauth/refresh-token) against CSRF.The package publishes:
dist/index.jsdist/index.cjsdist/index.d.tsnpm run clean
npm run build
npm test
npm run test:coverage
npm run lint
Demo scaffold:
npm run build
node demo/example.mjs
Package publishing is performed through GitHub CD workflows only. Do not publish directly from local machines.
FAQs
Authentication helpers and React context for Plasius applications.
We found that @plasius/auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.