@useauthio/react 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to `@useauthio/react` are documented here. This
4
4
  project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
5
5
  and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.2.1] — 2026-06-13
8
+
9
+ ### Fixed
10
+ - **Package is now installable from npm.** `0.2.0` declared its
11
+ `@useauthio/node` dependency as `file:./vendor/authio-node`, a local
12
+ path that does not resolve when installed from the registry, so
13
+ `npm install @useauthio/react` failed for every external user. The
14
+ dependency now points at the published `@useauthio/node` (`^0.2.0`)
15
+ and the vendored copy has been removed from the package.
16
+
7
17
  ## [0.2.0] — 2026-06-12
8
18
 
9
19
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useauthio/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "React SDK for Authio: hooks, gates, and sign-in helpers for pure SPAs.",
5
5
  "author": "Authio",
6
6
  "license": "MIT",
@@ -24,7 +24,6 @@
24
24
  "files": [
25
25
  "dist",
26
26
  "src",
27
- "vendor",
28
27
  "README.md",
29
28
  "LICENSE",
30
29
  "CHANGELOG.md"
@@ -37,7 +36,7 @@
37
36
  "react-dom": ">=18"
38
37
  },
39
38
  "dependencies": {
40
- "@useauthio/node": "file:./vendor/authio-node"
39
+ "@useauthio/node": "^0.2.0"
41
40
  },
42
41
  "devDependencies": {
43
42
  "@testing-library/jest-dom": "^6.4.0",
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Authio
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,116 +0,0 @@
1
- <p align="center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset=".github/logo-dark.png">
4
- <img alt="Authio" src=".github/logo-light.png" width="220">
5
- </picture>
6
- </p>
7
-
8
- # @useauthio/node
9
-
10
- Server-side TypeScript SDK for Authio. Use it from any Node.js / Bun / Deno backend (Express, Fastify, Hono, NestJS, Next.js Route Handlers, ...) to verify sessions, manage users, organizations, memberships, invitations, and connections.
11
-
12
- ## Install
13
-
14
- ```bash
15
- pnpm add @useauthio/node
16
- # or: npm i @useauthio/node / yarn add @useauthio/node
17
- ```
18
-
19
- ## Quick start
20
-
21
- ```ts
22
- import { Authio } from "@useauthio/node";
23
-
24
- const authio = new Authio({ apiKey: process.env.AUTHIO_SECRET_KEY! });
25
-
26
- export async function handler(req: Request) {
27
- const session = await authio.sessions.verify(
28
- req.headers.get("cookie") ?? "",
29
- );
30
- if (!session) return new Response("Unauthorized", { status: 401 });
31
-
32
- // session.userId is always set; session.orgId is set only after the
33
- // user has selected an organization (multi-org users may have many).
34
- const memberships = await authio.users.listMemberships(session.userId);
35
- return Response.json({ user: session.userId, memberships });
36
- }
37
- ```
38
-
39
- ## Multi-org-aware
40
-
41
- `session.orgId` represents the currently-active organization for the request. A session is *user-scoped* — `session.userId` is the same regardless of which org the user is in. To switch:
42
-
43
- ```ts
44
- await authio.sessions.switchOrg(sessionId, { organizationId: "org_..." });
45
- ```
46
-
47
- This mints a new session bound to a different org without re-authenticating the user.
48
-
49
- ## Refresh tokens (BFF cookie auto-renewal)
50
-
51
- Authio mints two tokens at sign-in:
52
-
53
- - A **short-lived access JWT** (`access_token`, ~15 min) — what your `verify()` call checks.
54
- - A **long-lived refresh token** (`refresh_token`, default 30 days, capped per org-policy `refresh_window_min`) — used to mint a new access JWT silently.
55
-
56
- A typical BFF (Next.js / Express / Hono) stashes the access token in a short-lived cookie and the refresh token in a long-lived cookie, then rotates the access cookie before it expires using `Authio.sessions.refresh`:
57
-
58
- ```ts
59
- import { Authio, AuthioError } from "@useauthio/node";
60
-
61
- const authio = new Authio({ apiKey: process.env.AUTHIO_SECRET_KEY! });
62
-
63
- // Inside your /api/auth/refresh handler (or middleware):
64
- async function silentRenew(req: Request, res: Response) {
65
- try {
66
- const env = await authio.sessions.refresh({
67
- refreshToken: req.cookies["authio_refresh"],
68
- });
69
- res.cookie("authio_session", env.access_token, {
70
- httpOnly: true,
71
- secure: true,
72
- sameSite: "none",
73
- maxAge: 15 * 60 * 1000,
74
- });
75
- res.cookie("authio_refresh", env.refresh_token, {
76
- httpOnly: true,
77
- secure: true,
78
- sameSite: "none",
79
- maxAge: 30 * 24 * 60 * 60 * 1000,
80
- });
81
- } catch (err) {
82
- if (err instanceof AuthioError) {
83
- // Auth-core enforces three lifecycle knobs from the org-policy
84
- // engine. Surface stable codes back to your caller so
85
- // they can render the right "your admin requires re-auth" copy:
86
- // policy_violation_session_idle — idle gap > policy
87
- // policy_violation_session_absolute — session past absolute max
88
- // policy_violation_session_refresh_window — past refresh window
89
- // invalid_refresh_token — revoked / unknown / raced
90
- res.clearCookie("authio_session");
91
- res.clearCookie("authio_refresh");
92
- res.redirect(`/sign-in?err=${encodeURIComponent(err.code)}`);
93
- return;
94
- }
95
- throw err;
96
- }
97
- }
98
- ```
99
-
100
- The OLD refresh token is single-use — auth-core's rotation is atomic, so a stolen refresh can be replayed at most once. The session row's `expires_at` is also clamped to `issued_at + refresh_window_min` when an org-policy is configured, so refresh chains can never outlive the policy.
101
-
102
- ## Session lifecycle policy
103
-
104
- Customers can configure three knobs per organization on the dashboard `/orgs/<id>/security` page:
105
-
106
- | Knob | Meaning | Typical value |
107
- |---|---|---|
108
- | `session_idle_timeout_min` | Max gap from last activity before forcing re-auth | 30 (high-security) / 480 (consumer) |
109
- | `session_absolute_max_min` | Absolute max session lifetime since sign-in | 1440 (24h) / 14400 (10d) |
110
- | `refresh_window_min` | Cap on the rolling refresh-token chain | 720 (12h) / 10080 (7d) |
111
-
112
- A zero value on any knob means "inherit the project default". The strictest non-zero gate wins on every refresh.
113
-
114
- ## License
115
-
116
- MIT
@@ -1,230 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- Authio: () => Authio,
24
- AuthioError: () => AuthioError,
25
- JwtVerifier: () => JwtVerifier
26
- });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
- // src/errors.ts
30
- var AuthioError = class extends Error {
31
- code;
32
- status;
33
- requestId;
34
- constructor(opts) {
35
- super(opts.message);
36
- this.name = "AuthioError";
37
- this.code = opts.code;
38
- this.status = opts.status;
39
- this.requestId = opts.requestId;
40
- }
41
- };
42
-
43
- // src/jwks.ts
44
- var import_jose = require("jose");
45
- var JwtVerifier = class {
46
- constructor(apiUrl, issuer, audience) {
47
- this.apiUrl = apiUrl;
48
- this.issuer = issuer;
49
- this.audience = audience;
50
- this.jwks = (0, import_jose.createRemoteJWKSet)(
51
- new URL(this.apiUrl.replace(/\/$/, "") + "/v1/auth/.well-known/jwks.json"),
52
- {
53
- cooldownDuration: 3e4,
54
- cacheMaxAge: 6e5
55
- }
56
- );
57
- }
58
- apiUrl;
59
- issuer;
60
- audience;
61
- jwks;
62
- async verify(token) {
63
- const { payload } = await (0, import_jose.jwtVerify)(token, this.jwks, {
64
- issuer: this.issuer,
65
- audience: this.audience,
66
- algorithms: ["EdDSA"]
67
- });
68
- if (!payload.sub) {
69
- throw new Error("authio: token missing sub claim");
70
- }
71
- return payload;
72
- }
73
- };
74
-
75
- // src/client.ts
76
- var DEFAULT_API_URL = "https://api.authio.com";
77
- var DEFAULT_ISSUER = "https://api.authio.com";
78
- var DEFAULT_AUDIENCE = "authio";
79
- var Authio = class {
80
- constructor(options) {
81
- this.options = options;
82
- if (!options.apiKey) {
83
- throw new Error(
84
- "Authio: apiKey is required. Pass it directly or set AUTHIO_SECRET_KEY."
85
- );
86
- }
87
- const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
88
- this.verifier = new JwtVerifier(
89
- apiUrl,
90
- options.jwtIssuer ?? DEFAULT_ISSUER,
91
- options.jwtAudience ?? DEFAULT_AUDIENCE
92
- );
93
- this.sessions = new SessionsAPI(this, this.verifier);
94
- }
95
- options;
96
- users = new UsersAPI(this);
97
- organizations = new OrganizationsAPI(this);
98
- memberships = new MembershipsAPI(this);
99
- sessions;
100
- verifier;
101
- async request(method, path, body) {
102
- const url = (this.options.apiUrl ?? DEFAULT_API_URL) + path;
103
- const fetchFn = this.options.fetch ?? globalThis.fetch;
104
- const res = await fetchFn(url, {
105
- method,
106
- headers: {
107
- "content-type": "application/json",
108
- "user-agent": "authio-node/0.1.0",
109
- authorization: `Bearer ${this.options.apiKey}`
110
- },
111
- body: body ? JSON.stringify(body) : void 0
112
- });
113
- if (!res.ok) {
114
- const data = await res.json().catch(() => ({}));
115
- throw new AuthioError({
116
- code: data.code ?? "request_failed",
117
- message: data.message ?? `Request failed with status ${res.status}`,
118
- status: res.status,
119
- requestId: data.request_id
120
- });
121
- }
122
- if (res.status === 204) return void 0;
123
- return await res.json();
124
- }
125
- };
126
- var UsersAPI = class {
127
- constructor(client) {
128
- this.client = client;
129
- }
130
- client;
131
- get(userId) {
132
- return this.client.request("GET", `/v1/users/${userId}`);
133
- }
134
- listMemberships(userId) {
135
- return this.client.request(
136
- "GET",
137
- `/v1/users/${userId}/memberships`
138
- );
139
- }
140
- };
141
- var OrganizationsAPI = class {
142
- constructor(client) {
143
- this.client = client;
144
- }
145
- client;
146
- list() {
147
- return this.client.request("GET", "/v1/organizations");
148
- }
149
- create(input) {
150
- return this.client.request("POST", "/v1/organizations", input);
151
- }
152
- get(orgId) {
153
- return this.client.request("GET", `/v1/organizations/${orgId}`);
154
- }
155
- };
156
- var MembershipsAPI = class {
157
- constructor(client) {
158
- this.client = client;
159
- }
160
- client;
161
- listForOrganization(orgId) {
162
- return this.client.request(
163
- "GET",
164
- `/v1/organizations/${orgId}/memberships`
165
- );
166
- }
167
- add(orgId, input) {
168
- return this.client.request(
169
- "POST",
170
- `/v1/organizations/${orgId}/memberships`,
171
- { user_id: input.userId, role: input.role }
172
- );
173
- }
174
- remove(orgId, membershipId) {
175
- return this.client.request(
176
- "DELETE",
177
- `/v1/organizations/${orgId}/memberships/${membershipId}`
178
- );
179
- }
180
- };
181
- var SessionsAPI = class {
182
- constructor(client, verifier) {
183
- this.client = client;
184
- this.verifier = verifier;
185
- }
186
- client;
187
- verifier;
188
- /**
189
- * Verify an Authio access token (JWT). Returns the typed Session, or
190
- * null when the token is invalid/expired.
191
- *
192
- * `session.userId` is always set; `session.orgId` may be null when the
193
- * user has authenticated but not yet selected an organization (multi-org
194
- * users coming straight out of /v1/auth/passkey/login/verify).
195
- */
196
- async verify(accessToken) {
197
- if (!accessToken) return null;
198
- try {
199
- const claims = await this.verifier.verify(accessToken);
200
- return {
201
- sessionId: claims.sid ?? "",
202
- userId: claims.sub,
203
- orgId: claims.act_org ? claims.act_org : null,
204
- role: claims.act_role ? claims.act_role : null,
205
- expiresAt: claims.exp ? new Date(claims.exp * 1e3).toISOString() : (/* @__PURE__ */ new Date()).toISOString()
206
- };
207
- } catch {
208
- return null;
209
- }
210
- }
211
- /** Pivot a session into a different organization without re-authentication. */
212
- switchOrg(_sessionId, input) {
213
- return this.client.request(
214
- "POST",
215
- "/v1/sessions/switch-org",
216
- { organization_id: input.organizationId }
217
- );
218
- }
219
- revoke(sessionId) {
220
- return this.client.request("POST", "/v1/sessions/revoke", {
221
- session_id: sessionId
222
- });
223
- }
224
- };
225
- // Annotate the CommonJS export names for ESM import in node:
226
- 0 && (module.exports = {
227
- Authio,
228
- AuthioError,
229
- JwtVerifier
230
- });
@@ -1,150 +0,0 @@
1
- import { JWTPayload } from 'jose';
2
-
3
- interface AuthioClaims extends JWTPayload {
4
- sub: string;
5
- /** The active organization for this token. Empty string if the user has not yet selected an org. */
6
- act_org?: string;
7
- /** The active role within `act_org`. */
8
- act_role?: string;
9
- /** Session ID. */
10
- sid?: string;
11
- }
12
- /**
13
- * Verifier wraps a remote JWKS fetcher with caching. Spawn one per
14
- * `apiUrl` and reuse — fetching JWKS on every request is wasteful.
15
- */
16
- declare class JwtVerifier {
17
- private readonly apiUrl;
18
- private readonly issuer;
19
- private readonly audience;
20
- private readonly jwks;
21
- constructor(apiUrl: string, issuer: string, audience: string);
22
- verify(token: string): Promise<AuthioClaims>;
23
- }
24
-
25
- interface User {
26
- id: string;
27
- projectId: string;
28
- email: string;
29
- emailVerified: boolean;
30
- name?: string;
31
- avatarUrl?: string;
32
- defaultOrganizationId: string | null;
33
- createdAt: string;
34
- updatedAt: string;
35
- }
36
- interface Organization {
37
- id: string;
38
- projectId: string;
39
- name: string;
40
- slug: string;
41
- createdAt: string;
42
- }
43
- type MembershipStatus = "invited" | "active" | "suspended" | "deactivated";
44
- interface Membership {
45
- id: string;
46
- projectId: string;
47
- userId: string;
48
- organizationId: string;
49
- role: string;
50
- status: MembershipStatus;
51
- joinedAt: string;
52
- invitedBy: string | null;
53
- lastActiveAt: string | null;
54
- preferredLoginMethod: "passkey" | "magic_link" | "oauth" | "sso" | null;
55
- }
56
- /**
57
- * A verified Authio session.
58
- *
59
- * The session always identifies the *user* (`userId`); the active
60
- * organization (`orgId`) is only set after the user has selected one of
61
- * their memberships. A user with multiple memberships may move between
62
- * orgs in-session without re-authenticating.
63
- */
64
- interface Session {
65
- sessionId: string;
66
- userId: string;
67
- orgId: string | null;
68
- role: string | null;
69
- expiresAt: string;
70
- }
71
-
72
- interface AuthioOptions {
73
- apiKey: string;
74
- apiUrl?: string;
75
- /** JWT issuer to require. Defaults to the production issuer. */
76
- jwtIssuer?: string;
77
- /** JWT audience to require. */
78
- jwtAudience?: string;
79
- fetch?: typeof fetch;
80
- }
81
- declare class Authio {
82
- readonly options: AuthioOptions;
83
- readonly users: UsersAPI;
84
- readonly organizations: OrganizationsAPI;
85
- readonly memberships: MembershipsAPI;
86
- readonly sessions: SessionsAPI;
87
- private readonly verifier;
88
- constructor(options: AuthioOptions);
89
- request<T>(method: string, path: string, body?: unknown): Promise<T>;
90
- }
91
- declare class UsersAPI {
92
- private readonly client;
93
- constructor(client: Authio);
94
- get(userId: string): Promise<User>;
95
- listMemberships(userId: string): Promise<Membership[]>;
96
- }
97
- declare class OrganizationsAPI {
98
- private readonly client;
99
- constructor(client: Authio);
100
- list(): Promise<Organization[]>;
101
- create(input: {
102
- name: string;
103
- slug?: string;
104
- domain?: string;
105
- }): Promise<Organization>;
106
- get(orgId: string): Promise<Organization>;
107
- }
108
- declare class MembershipsAPI {
109
- private readonly client;
110
- constructor(client: Authio);
111
- listForOrganization(orgId: string): Promise<Membership[]>;
112
- add(orgId: string, input: {
113
- userId: string;
114
- role: string;
115
- }): Promise<Membership>;
116
- remove(orgId: string, membershipId: string): Promise<void>;
117
- }
118
- declare class SessionsAPI {
119
- private readonly client;
120
- private readonly verifier;
121
- constructor(client: Authio, verifier: JwtVerifier);
122
- /**
123
- * Verify an Authio access token (JWT). Returns the typed Session, or
124
- * null when the token is invalid/expired.
125
- *
126
- * `session.userId` is always set; `session.orgId` may be null when the
127
- * user has authenticated but not yet selected an organization (multi-org
128
- * users coming straight out of /v1/auth/passkey/login/verify).
129
- */
130
- verify(accessToken: string): Promise<Session | null>;
131
- /** Pivot a session into a different organization without re-authentication. */
132
- switchOrg(_sessionId: string, input: {
133
- organizationId: string;
134
- }): Promise<Session>;
135
- revoke(sessionId: string): Promise<void>;
136
- }
137
-
138
- declare class AuthioError extends Error {
139
- readonly code: string;
140
- readonly status: number;
141
- readonly requestId?: string;
142
- constructor(opts: {
143
- code: string;
144
- message: string;
145
- status: number;
146
- requestId?: string;
147
- });
148
- }
149
-
150
- export { Authio, type AuthioClaims, AuthioError, type AuthioOptions, JwtVerifier, type Membership, type Organization, type Session, type User };
@@ -1,150 +0,0 @@
1
- import { JWTPayload } from 'jose';
2
-
3
- interface AuthioClaims extends JWTPayload {
4
- sub: string;
5
- /** The active organization for this token. Empty string if the user has not yet selected an org. */
6
- act_org?: string;
7
- /** The active role within `act_org`. */
8
- act_role?: string;
9
- /** Session ID. */
10
- sid?: string;
11
- }
12
- /**
13
- * Verifier wraps a remote JWKS fetcher with caching. Spawn one per
14
- * `apiUrl` and reuse — fetching JWKS on every request is wasteful.
15
- */
16
- declare class JwtVerifier {
17
- private readonly apiUrl;
18
- private readonly issuer;
19
- private readonly audience;
20
- private readonly jwks;
21
- constructor(apiUrl: string, issuer: string, audience: string);
22
- verify(token: string): Promise<AuthioClaims>;
23
- }
24
-
25
- interface User {
26
- id: string;
27
- projectId: string;
28
- email: string;
29
- emailVerified: boolean;
30
- name?: string;
31
- avatarUrl?: string;
32
- defaultOrganizationId: string | null;
33
- createdAt: string;
34
- updatedAt: string;
35
- }
36
- interface Organization {
37
- id: string;
38
- projectId: string;
39
- name: string;
40
- slug: string;
41
- createdAt: string;
42
- }
43
- type MembershipStatus = "invited" | "active" | "suspended" | "deactivated";
44
- interface Membership {
45
- id: string;
46
- projectId: string;
47
- userId: string;
48
- organizationId: string;
49
- role: string;
50
- status: MembershipStatus;
51
- joinedAt: string;
52
- invitedBy: string | null;
53
- lastActiveAt: string | null;
54
- preferredLoginMethod: "passkey" | "magic_link" | "oauth" | "sso" | null;
55
- }
56
- /**
57
- * A verified Authio session.
58
- *
59
- * The session always identifies the *user* (`userId`); the active
60
- * organization (`orgId`) is only set after the user has selected one of
61
- * their memberships. A user with multiple memberships may move between
62
- * orgs in-session without re-authenticating.
63
- */
64
- interface Session {
65
- sessionId: string;
66
- userId: string;
67
- orgId: string | null;
68
- role: string | null;
69
- expiresAt: string;
70
- }
71
-
72
- interface AuthioOptions {
73
- apiKey: string;
74
- apiUrl?: string;
75
- /** JWT issuer to require. Defaults to the production issuer. */
76
- jwtIssuer?: string;
77
- /** JWT audience to require. */
78
- jwtAudience?: string;
79
- fetch?: typeof fetch;
80
- }
81
- declare class Authio {
82
- readonly options: AuthioOptions;
83
- readonly users: UsersAPI;
84
- readonly organizations: OrganizationsAPI;
85
- readonly memberships: MembershipsAPI;
86
- readonly sessions: SessionsAPI;
87
- private readonly verifier;
88
- constructor(options: AuthioOptions);
89
- request<T>(method: string, path: string, body?: unknown): Promise<T>;
90
- }
91
- declare class UsersAPI {
92
- private readonly client;
93
- constructor(client: Authio);
94
- get(userId: string): Promise<User>;
95
- listMemberships(userId: string): Promise<Membership[]>;
96
- }
97
- declare class OrganizationsAPI {
98
- private readonly client;
99
- constructor(client: Authio);
100
- list(): Promise<Organization[]>;
101
- create(input: {
102
- name: string;
103
- slug?: string;
104
- domain?: string;
105
- }): Promise<Organization>;
106
- get(orgId: string): Promise<Organization>;
107
- }
108
- declare class MembershipsAPI {
109
- private readonly client;
110
- constructor(client: Authio);
111
- listForOrganization(orgId: string): Promise<Membership[]>;
112
- add(orgId: string, input: {
113
- userId: string;
114
- role: string;
115
- }): Promise<Membership>;
116
- remove(orgId: string, membershipId: string): Promise<void>;
117
- }
118
- declare class SessionsAPI {
119
- private readonly client;
120
- private readonly verifier;
121
- constructor(client: Authio, verifier: JwtVerifier);
122
- /**
123
- * Verify an Authio access token (JWT). Returns the typed Session, or
124
- * null when the token is invalid/expired.
125
- *
126
- * `session.userId` is always set; `session.orgId` may be null when the
127
- * user has authenticated but not yet selected an organization (multi-org
128
- * users coming straight out of /v1/auth/passkey/login/verify).
129
- */
130
- verify(accessToken: string): Promise<Session | null>;
131
- /** Pivot a session into a different organization without re-authentication. */
132
- switchOrg(_sessionId: string, input: {
133
- organizationId: string;
134
- }): Promise<Session>;
135
- revoke(sessionId: string): Promise<void>;
136
- }
137
-
138
- declare class AuthioError extends Error {
139
- readonly code: string;
140
- readonly status: number;
141
- readonly requestId?: string;
142
- constructor(opts: {
143
- code: string;
144
- message: string;
145
- status: number;
146
- requestId?: string;
147
- });
148
- }
149
-
150
- export { Authio, type AuthioClaims, AuthioError, type AuthioOptions, JwtVerifier, type Membership, type Organization, type Session, type User };
@@ -1,201 +0,0 @@
1
- // src/errors.ts
2
- var AuthioError = class extends Error {
3
- code;
4
- status;
5
- requestId;
6
- constructor(opts) {
7
- super(opts.message);
8
- this.name = "AuthioError";
9
- this.code = opts.code;
10
- this.status = opts.status;
11
- this.requestId = opts.requestId;
12
- }
13
- };
14
-
15
- // src/jwks.ts
16
- import { createRemoteJWKSet, jwtVerify } from "jose";
17
- var JwtVerifier = class {
18
- constructor(apiUrl, issuer, audience) {
19
- this.apiUrl = apiUrl;
20
- this.issuer = issuer;
21
- this.audience = audience;
22
- this.jwks = createRemoteJWKSet(
23
- new URL(this.apiUrl.replace(/\/$/, "") + "/v1/auth/.well-known/jwks.json"),
24
- {
25
- cooldownDuration: 3e4,
26
- cacheMaxAge: 6e5
27
- }
28
- );
29
- }
30
- apiUrl;
31
- issuer;
32
- audience;
33
- jwks;
34
- async verify(token) {
35
- const { payload } = await jwtVerify(token, this.jwks, {
36
- issuer: this.issuer,
37
- audience: this.audience,
38
- algorithms: ["EdDSA"]
39
- });
40
- if (!payload.sub) {
41
- throw new Error("authio: token missing sub claim");
42
- }
43
- return payload;
44
- }
45
- };
46
-
47
- // src/client.ts
48
- var DEFAULT_API_URL = "https://api.authio.com";
49
- var DEFAULT_ISSUER = "https://api.authio.com";
50
- var DEFAULT_AUDIENCE = "authio";
51
- var Authio = class {
52
- constructor(options) {
53
- this.options = options;
54
- if (!options.apiKey) {
55
- throw new Error(
56
- "Authio: apiKey is required. Pass it directly or set AUTHIO_SECRET_KEY."
57
- );
58
- }
59
- const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
60
- this.verifier = new JwtVerifier(
61
- apiUrl,
62
- options.jwtIssuer ?? DEFAULT_ISSUER,
63
- options.jwtAudience ?? DEFAULT_AUDIENCE
64
- );
65
- this.sessions = new SessionsAPI(this, this.verifier);
66
- }
67
- options;
68
- users = new UsersAPI(this);
69
- organizations = new OrganizationsAPI(this);
70
- memberships = new MembershipsAPI(this);
71
- sessions;
72
- verifier;
73
- async request(method, path, body) {
74
- const url = (this.options.apiUrl ?? DEFAULT_API_URL) + path;
75
- const fetchFn = this.options.fetch ?? globalThis.fetch;
76
- const res = await fetchFn(url, {
77
- method,
78
- headers: {
79
- "content-type": "application/json",
80
- "user-agent": "authio-node/0.1.0",
81
- authorization: `Bearer ${this.options.apiKey}`
82
- },
83
- body: body ? JSON.stringify(body) : void 0
84
- });
85
- if (!res.ok) {
86
- const data = await res.json().catch(() => ({}));
87
- throw new AuthioError({
88
- code: data.code ?? "request_failed",
89
- message: data.message ?? `Request failed with status ${res.status}`,
90
- status: res.status,
91
- requestId: data.request_id
92
- });
93
- }
94
- if (res.status === 204) return void 0;
95
- return await res.json();
96
- }
97
- };
98
- var UsersAPI = class {
99
- constructor(client) {
100
- this.client = client;
101
- }
102
- client;
103
- get(userId) {
104
- return this.client.request("GET", `/v1/users/${userId}`);
105
- }
106
- listMemberships(userId) {
107
- return this.client.request(
108
- "GET",
109
- `/v1/users/${userId}/memberships`
110
- );
111
- }
112
- };
113
- var OrganizationsAPI = class {
114
- constructor(client) {
115
- this.client = client;
116
- }
117
- client;
118
- list() {
119
- return this.client.request("GET", "/v1/organizations");
120
- }
121
- create(input) {
122
- return this.client.request("POST", "/v1/organizations", input);
123
- }
124
- get(orgId) {
125
- return this.client.request("GET", `/v1/organizations/${orgId}`);
126
- }
127
- };
128
- var MembershipsAPI = class {
129
- constructor(client) {
130
- this.client = client;
131
- }
132
- client;
133
- listForOrganization(orgId) {
134
- return this.client.request(
135
- "GET",
136
- `/v1/organizations/${orgId}/memberships`
137
- );
138
- }
139
- add(orgId, input) {
140
- return this.client.request(
141
- "POST",
142
- `/v1/organizations/${orgId}/memberships`,
143
- { user_id: input.userId, role: input.role }
144
- );
145
- }
146
- remove(orgId, membershipId) {
147
- return this.client.request(
148
- "DELETE",
149
- `/v1/organizations/${orgId}/memberships/${membershipId}`
150
- );
151
- }
152
- };
153
- var SessionsAPI = class {
154
- constructor(client, verifier) {
155
- this.client = client;
156
- this.verifier = verifier;
157
- }
158
- client;
159
- verifier;
160
- /**
161
- * Verify an Authio access token (JWT). Returns the typed Session, or
162
- * null when the token is invalid/expired.
163
- *
164
- * `session.userId` is always set; `session.orgId` may be null when the
165
- * user has authenticated but not yet selected an organization (multi-org
166
- * users coming straight out of /v1/auth/passkey/login/verify).
167
- */
168
- async verify(accessToken) {
169
- if (!accessToken) return null;
170
- try {
171
- const claims = await this.verifier.verify(accessToken);
172
- return {
173
- sessionId: claims.sid ?? "",
174
- userId: claims.sub,
175
- orgId: claims.act_org ? claims.act_org : null,
176
- role: claims.act_role ? claims.act_role : null,
177
- expiresAt: claims.exp ? new Date(claims.exp * 1e3).toISOString() : (/* @__PURE__ */ new Date()).toISOString()
178
- };
179
- } catch {
180
- return null;
181
- }
182
- }
183
- /** Pivot a session into a different organization without re-authentication. */
184
- switchOrg(_sessionId, input) {
185
- return this.client.request(
186
- "POST",
187
- "/v1/sessions/switch-org",
188
- { organization_id: input.organizationId }
189
- );
190
- }
191
- revoke(sessionId) {
192
- return this.client.request("POST", "/v1/sessions/revoke", {
193
- session_id: sessionId
194
- });
195
- }
196
- };
197
- export {
198
- Authio,
199
- AuthioError,
200
- JwtVerifier
201
- };
@@ -1,31 +0,0 @@
1
- {
2
- "name": "@useauthio/node",
3
- "version": "0.1.0",
4
- "description": "Authio server-side SDK for Node.js, Bun, Deno, and edge runtimes. Vendored from authio-com/authio_node so @useauthio/react can resolve it locally before the npm scope is claimed.",
5
- "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/authio-com/authio_node.git"
9
- },
10
- "type": "module",
11
- "main": "./dist/index.js",
12
- "types": "./dist/index.d.ts",
13
- "exports": {
14
- ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js",
17
- "require": "./dist/index.cjs"
18
- }
19
- },
20
- "files": [
21
- "dist",
22
- "README.md",
23
- "LICENSE"
24
- ],
25
- "dependencies": {
26
- "jose": "^5.9.0"
27
- },
28
- "engines": {
29
- "node": ">=20"
30
- }
31
- }