@zukhruf/authentication 0.0.0-stage → 0.8.36
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/LICENSE +21 -0
- package/README.md +194 -2
- package/dist/hono.d.ts +56 -0
- package/dist/hono.d.ts.map +1 -0
- package/dist/hono.js +53 -0
- package/dist/hono.js.map +1 -0
- package/dist/react-router.d.ts +60 -0
- package/dist/react-router.d.ts.map +1 -0
- package/dist/react-router.js +91 -0
- package/dist/react-router.js.map +1 -0
- package/package.json +63 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ezzabuzaid
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,195 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zukhruf/authentication
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Ezz accepted each ADR on 2026-11-19. Built and tested, not yet on npm.
|
|
4
|
+
|
|
5
|
+
An app that signs its users in with [better-auth](https://www.better-auth.com) asks the same two questions on every request: who sent it, and may it pass. This package answers both at the edges of the app. On the server, a Hono middleware reads the better-auth session from the request and refuses a request without one. In the browser, a React Router loader sends a visitor without a session to the sign-in page, and brings them back to the page they asked for, never to another site.
|
|
6
|
+
|
|
7
|
+
better-auth owns the sign-in itself: the methods, the cookies, the tables and the second factor. This package only reads what better-auth decided.
|
|
8
|
+
|
|
9
|
+
The words in these documents have one meaning each. See the glossary in [GLOSSARY.md](./GLOSSARY.md).
|
|
10
|
+
|
|
11
|
+
## Use it
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @zukhruf/authentication hono react-router
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Refuse a request without a session (Hono)
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Hono } from 'hono';
|
|
21
|
+
|
|
22
|
+
import { requireSession } from '@zukhruf/authentication/hono';
|
|
23
|
+
|
|
24
|
+
import { auth } from './auth.ts';
|
|
25
|
+
|
|
26
|
+
// betterAuth({ … })
|
|
27
|
+
|
|
28
|
+
const app = new Hono();
|
|
29
|
+
|
|
30
|
+
app.on(['GET', 'POST'], '/api/auth/*', (c) => auth.handler(c.req.raw));
|
|
31
|
+
|
|
32
|
+
// Everything under /api needs a session, and a user with two-factor turned on.
|
|
33
|
+
// Hono types c.var.session on the routes chained after use(), or on a route
|
|
34
|
+
// that lists the middleware itself.
|
|
35
|
+
app
|
|
36
|
+
.use('/api/*', requireSession(auth, { twoFactor: true }))
|
|
37
|
+
.get('/api/me', (c) => c.json(c.var.session.user)); // not null here
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A route that a guest may read too calls `auth.api.getSession({ headers: c.req.raw.headers })` itself: better-auth already reads the session, so the package only requires one ([ADR 0002](./docs/adr/0002-the-package-only-requires-a-session-and-better-auths-getsession-reads-one.md)).
|
|
41
|
+
|
|
42
|
+
A request without a session gets `UnauthenticatedError` (401). A signed-in user without two-factor gets `TwoFactorRequiredError` (403). Both are `HTTPException`s, so the app's `onError` answers them as it answers every other `HTTPException` ([ADR 0004](./docs/adr/0004-a-refusal-is-an-httpexception-401-without-a-session-and-403-without-two-factor.md)).
|
|
43
|
+
|
|
44
|
+
### Send a visitor to sign in, and back (React Router)
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { twoFactorClient } from 'better-auth/client/plugins';
|
|
48
|
+
import { createAuthClient } from 'better-auth/react';
|
|
49
|
+
import type { LoaderFunctionArgs } from 'react-router';
|
|
50
|
+
|
|
51
|
+
import {
|
|
52
|
+
REDIRECT_TO,
|
|
53
|
+
requireSession,
|
|
54
|
+
safeRedirect,
|
|
55
|
+
} from '@zukhruf/authentication/react-router';
|
|
56
|
+
|
|
57
|
+
export const authClient = createAuthClient({ plugins: [twoFactorClient()] });
|
|
58
|
+
|
|
59
|
+
// The loader of every page behind sign-in.
|
|
60
|
+
export function protectedLoader({ request }: LoaderFunctionArgs) {
|
|
61
|
+
return requireSession(authClient, request, {
|
|
62
|
+
signIn: '/sign-in',
|
|
63
|
+
twoFactorSetup: '/two-factor/setup',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// The sign-in page, after a successful sign-in.
|
|
68
|
+
const target = safeRedirect(searchParams.get(REDIRECT_TO), {
|
|
69
|
+
origin: location.origin,
|
|
70
|
+
fallback: '/',
|
|
71
|
+
exclude: ['/sign-in', '/two-factor/setup'],
|
|
72
|
+
});
|
|
73
|
+
navigate(target, { replace: true });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A visitor on `/cases/42?tab=notes` without a session lands on `/sign-in?redirectTo=%2Fcases%2F42%3Ftab%3Dnotes`. When better-auth cannot answer (the network or the server is down), the loader throws `AuthenticationUnavailableError` for the route's error element, instead of sending a signed-in user to sign in ([ADR 0006](./docs/adr/0006-a-failed-session-read-is-authentication-unavailable-never-signed-out.md)).
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
// @zukhruf/authentication/hono
|
|
82
|
+
interface SessionSource<S> {
|
|
83
|
+
api: { getSession(context: { headers: Headers }): Promise<S | null> };
|
|
84
|
+
} // the member of a better-auth instance that the package calls
|
|
85
|
+
|
|
86
|
+
type RequireSessionOptions<S extends { user: object }> =
|
|
87
|
+
'twoFactorEnabled' extends keyof S['user']
|
|
88
|
+
? { readonly twoFactor?: boolean }
|
|
89
|
+
: { readonly twoFactor?: never }; // `twoFactor` only with better-auth's two-factor plugin
|
|
90
|
+
|
|
91
|
+
function requireSession<S extends { user: object }>(
|
|
92
|
+
auth: SessionSource<S>,
|
|
93
|
+
options?: RequireSessionOptions<S>,
|
|
94
|
+
): MiddlewareHandler<{ Variables: { session: S } }>;
|
|
95
|
+
|
|
96
|
+
class UnauthenticatedError extends HTTPException {} // 401, cause { code: 'auth/unauthenticated', detail }
|
|
97
|
+
class TwoFactorRequiredError extends HTTPException {} // 403, cause { code: 'auth/two-factor-required', detail }
|
|
98
|
+
|
|
99
|
+
// @zukhruf/authentication/react-router
|
|
100
|
+
interface SessionClient<S> {
|
|
101
|
+
getSession(): Promise<{ data: S | null; error: { status: number } | null }>;
|
|
102
|
+
} // the member of a better-auth client that the package calls
|
|
103
|
+
|
|
104
|
+
type RequireSessionOptions<S extends { user: object }> = {
|
|
105
|
+
readonly signIn: string;
|
|
106
|
+
} & ('twoFactorEnabled' extends keyof S['user']
|
|
107
|
+
? { readonly twoFactorSetup?: string }
|
|
108
|
+
: { readonly twoFactorSetup?: never }); // `twoFactorSetup` only with better-auth's two-factor plugin
|
|
109
|
+
|
|
110
|
+
function requireSession<S extends { user: object }>(
|
|
111
|
+
client: SessionClient<S>,
|
|
112
|
+
request: Request,
|
|
113
|
+
options: RequireSessionOptions<S>,
|
|
114
|
+
): Promise<S>;
|
|
115
|
+
|
|
116
|
+
interface SafeRedirectOptions {
|
|
117
|
+
readonly origin: string;
|
|
118
|
+
readonly fallback: string;
|
|
119
|
+
readonly exclude?: readonly string[];
|
|
120
|
+
}
|
|
121
|
+
function safeRedirect(
|
|
122
|
+
to: string | null | undefined,
|
|
123
|
+
options: SafeRedirectOptions,
|
|
124
|
+
): string;
|
|
125
|
+
|
|
126
|
+
const REDIRECT_TO = 'redirectTo';
|
|
127
|
+
class AuthenticationUnavailableError extends Error {} // `cause`: the rejection or the error response
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The package imports nothing from better-auth. `SessionSource` and `SessionClient` are structural, and `S` comes from the instance that the app passes, so `c.var.session` has the app's own user fields (`role`, `twoFactorEnabled`, …). The tests prove this against better-auth 1.7.26: a `betterAuth({ … })` instance and a `createAuthClient({ … })` client fit as they are.
|
|
131
|
+
|
|
132
|
+
The guard expects the default client, whose `getSession()` answers `{ data, error }`. A client made with `fetchOptions: { throw: true }` answers the session itself and throws on an error, so it does not type-check as a `SessionClient`.
|
|
133
|
+
|
|
134
|
+
## What a call does underneath
|
|
135
|
+
|
|
136
|
+
| Call | What happens |
|
|
137
|
+
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
138
|
+
| `requireSession(auth)` | `auth.api.getSession({ headers: c.req.raw.headers })` once. `null` throws `UnauthenticatedError`; a session goes on `c.var.session`. An error of `getSession` (the database is down) reaches the app as it is |
|
|
139
|
+
| `requireSession(auth, { twoFactor: true })` | as above, then `session.user.twoFactorEnabled !== true` throws `TwoFactorRequiredError`. better-auth gives no session to a user who turned two-factor on and did not enter the code, so a session either passed the second factor or belongs to a user who never turned it on |
|
|
140
|
+
| React Router `requireSession` | one `client.getSession()`. A rejection or an `error` throws `AuthenticationUnavailableError`. No session throws `replace(signIn + '?redirectTo=' + path)`. A user without two-factor, when `twoFactorSetup` is given, throws `replace(twoFactorSetup + '?redirectTo=' + path)`. On the `twoFactorSetup` page itself the two-factor check passes, so the page never redirects to itself. Otherwise it returns the session |
|
|
141
|
+
| the return path | `pathname + search` of `request.url`. On a page in `signIn` or `twoFactorSetup` itself, the page's own safe `redirectTo` goes on, so no page sends a visitor back to sign in. A path longer than 2,048 characters is left out |
|
|
142
|
+
| `safeRedirect(to)` | the fallback, unless `to` starts with `/`, not with `//` or `/\`, is at most 2,048 characters, parses on `origin` to the same origin, and its path is not in `exclude`. Then the parsed `pathname + search + hash`, so a tab or newline that the parser drops cannot turn `/\t/evil.example` into `//evil.example` |
|
|
143
|
+
|
|
144
|
+
## Errors
|
|
145
|
+
|
|
146
|
+
| Error | When | What the caller does next |
|
|
147
|
+
| -------------------------------- | ---------------------------------------------------- | -------------------------------------------------- |
|
|
148
|
+
| `UnauthenticatedError` (401) | no session | sign in |
|
|
149
|
+
| `TwoFactorRequiredError` (403) | a session, but the user has not turned two-factor on | set up two-factor |
|
|
150
|
+
| `AuthenticationUnavailableError` | the browser could not read the session | try again later; the route's error element says so |
|
|
151
|
+
|
|
152
|
+
The two server errors carry `cause: { code, detail }`, the shape that the error handler of an `@zukhruf/nx:node-app` backend already answers with. An error of better-auth itself, or of the network on the server, reaches the caller as it is.
|
|
153
|
+
|
|
154
|
+
## The same concepts in other systems
|
|
155
|
+
|
|
156
|
+
| This package | ASP.NET Core | go-chi/jwtauth | Remix indie-stack | @hono/auth-js |
|
|
157
|
+
| ---------------------- | ----------------------------------------------------------------------------- | ----------------------- | ------------------------ | ----------------------- |
|
|
158
|
+
| `requireSession(auth)` | `[Authorize]`, `RequireAuthorization()` | `Authenticator(ja)` | `requireUserId(request)` | `verifyAuth()` |
|
|
159
|
+
| `{ twoFactor: true }` | a policy with `RequireClaim("amr", "mfa")`; a failed policy is `Forbid` (403) | none | none | none |
|
|
160
|
+
| `UnauthenticatedError` | `Challenge` (401 or the login page) | `http.Error(w, …, 401)` | `redirect('/login')` | `HTTPException(401)` |
|
|
161
|
+
| `REDIRECT_TO` | `ReturnUrl` | none | `redirectTo` | `callbackUrl` (Auth.js) |
|
|
162
|
+
| `safeRedirect` | `Url.IsLocalUrl` | none | `safeRedirect` | none |
|
|
163
|
+
|
|
164
|
+
## Why not an npm package
|
|
165
|
+
|
|
166
|
+
Checked on 2026-11-19 (searches "better-auth hono middleware", "better-auth react-router", "hono session middleware better-auth"):
|
|
167
|
+
|
|
168
|
+
| Package | Weekly downloads | Why it does not do the job |
|
|
169
|
+
| --------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
170
|
+
| `@hono/auth-js` | 21,599 | Auth.js sessions, not better-auth |
|
|
171
|
+
| `@hono/clerk-auth`, `@clerk/hono` | 78,893, 116,817 | Clerk sessions; resolves only, never refuses |
|
|
172
|
+
| `better-auth-cloudflare` | 37,358 | Cloudflare Workers, D1 and KV setup; no guard |
|
|
173
|
+
| `better-auth` | 20,758,844 | its Hono guide is a pattern to copy, not an export. Its `sessionMiddleware` and `freshSessionMiddleware` run inside its own endpoints, not in Hono. `better-auth/react` has `useSession`, but no loader guard |
|
|
174
|
+
|
|
175
|
+
Node has no session or authentication API (a search of the exports of every built-in module finds only TLS, inspector and SQLite sessions).
|
|
176
|
+
|
|
177
|
+
## Now, later, never
|
|
178
|
+
|
|
179
|
+
| Now | Later (two places today; waits for a third) | Never |
|
|
180
|
+
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
181
|
+
| a better-auth session on Hono: resolve and require | a bearer JWT from a better-auth JWKS (text2sql v2 and desktop `authxPass`) | the sign-in methods, pages and emails |
|
|
182
|
+
| two-factor required | an API key (thing `authenticateApiKey`, text2sql v1) | users, roles, organizations: authorization is its own concept |
|
|
183
|
+
| the React Router loader guard and the safe return path | a session younger than `freshAge`; a middleware that only reads the session (one place today: blackboard) | the tables and their migrations (better-auth's CLI and `@zukhruf/nx:auth`) |
|
|
184
|
+
| | React Router middleware (`context.set`), when a host uses it | an identity provider |
|
|
185
|
+
|
|
186
|
+
## Who moves onto it
|
|
187
|
+
|
|
188
|
+
| Program | Its copy today | After |
|
|
189
|
+
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
190
|
+
| meddit (#4721, #4722) | none | `requireSession(auth, { twoFactor: true })`; React Router `requireSession` with `twoFactorSetup` |
|
|
191
|
+
| text2sql v1 (#4726) | `authenticate` in `apps/backend/src/middlewares/middleware.ts` (session part); `requiresAuth` and `redirect-to.ts` in `apps/frontend/src/app/auth/` | `requireSession(auth)`, and its team middleware reads `c.var.session`; the frontend keeps its setup check before `requireSession` |
|
|
192
|
+
| thing (#4727) | `authenticate` in `apps/backend/src/middlewares/middleware.ts`; `requiresAuth` in `apps/frontend` and `apps/pulse` | `requireSession(auth)`; `authenticateEither` keeps its API-key branch and falls back to `requireSession` |
|
|
193
|
+
| blackboard (#4728) | `requireIdentity` and `redirectDestination` in `apps/web/src/auth.ts`; the `userId` middleware in `apps/api/src/app.ts` | React Router `requireSession` and `safeRedirect`; its `redirect` query parameter becomes `redirectTo` |
|
|
194
|
+
| text2sql authx, v2, desktop | an identity provider and its JWT clients | stay; the JWT is the "later" column |
|
|
195
|
+
| iworked, pm, Kortext regression | dormant or a client's repo | left out (Ezz, 2026-11-19) |
|
package/dist/hono.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
import { HTTPException } from 'hono/http-exception';
|
|
3
|
+
/**
|
|
4
|
+
* The member of a better-auth instance that the middleware calls. A
|
|
5
|
+
* `betterAuth({ … })` instance is one, and `S` is its session type, with the
|
|
6
|
+
* app's own user fields.
|
|
7
|
+
*/
|
|
8
|
+
export interface SessionSource<S> {
|
|
9
|
+
api: {
|
|
10
|
+
getSession(context: {
|
|
11
|
+
headers: Headers;
|
|
12
|
+
}): Promise<S | null>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `twoFactor` exists only when the session's user has `twoFactorEnabled`,
|
|
17
|
+
* which better-auth's two-factor plugin adds, so an app without the plugin
|
|
18
|
+
* cannot ask for it.
|
|
19
|
+
*/
|
|
20
|
+
export type RequireSessionOptions<S extends {
|
|
21
|
+
user: object;
|
|
22
|
+
}> = 'twoFactorEnabled' extends keyof S['user'] ? {
|
|
23
|
+
readonly twoFactor?: boolean;
|
|
24
|
+
} : {
|
|
25
|
+
readonly twoFactor?: never;
|
|
26
|
+
};
|
|
27
|
+
/** A request without a session: 401, the caller signs in. */
|
|
28
|
+
export declare class UnauthenticatedError extends HTTPException {
|
|
29
|
+
readonly cause: {
|
|
30
|
+
code: 'auth/unauthenticated';
|
|
31
|
+
detail: string;
|
|
32
|
+
};
|
|
33
|
+
constructor();
|
|
34
|
+
}
|
|
35
|
+
/** A session whose user has not turned two-factor on: 403, the caller sets it up. */
|
|
36
|
+
export declare class TwoFactorRequiredError extends HTTPException {
|
|
37
|
+
readonly cause: {
|
|
38
|
+
code: 'auth/two-factor-required';
|
|
39
|
+
detail: string;
|
|
40
|
+
};
|
|
41
|
+
constructor();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Refuses a request without a session, and, with `twoFactor: true`, a session
|
|
45
|
+
* whose user has not turned two-factor on. A request that passes has the
|
|
46
|
+
* session on `c.var.session`. An error of `getSession` (the database is down)
|
|
47
|
+
* reaches the app as it is.
|
|
48
|
+
*/
|
|
49
|
+
export declare function requireSession<S extends {
|
|
50
|
+
user: object;
|
|
51
|
+
}>(auth: SessionSource<S>, options?: RequireSessionOptions<S>): MiddlewareHandler<{
|
|
52
|
+
Variables: {
|
|
53
|
+
session: S;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
//# sourceMappingURL=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AAE,OAAO,EAAE,CAAC,CAAA;KAAE,CAAA;CAAE,CAAC,CAWlD"}
|
package/dist/hono.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createMiddleware } from 'hono/factory';
|
|
2
|
+
import { HTTPException } from 'hono/http-exception';
|
|
3
|
+
/** A request without a session: 401, the caller signs in. */
|
|
4
|
+
export class UnauthenticatedError extends HTTPException {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(401, {
|
|
7
|
+
message: 'Authentication required',
|
|
8
|
+
cause: {
|
|
9
|
+
code: 'auth/unauthenticated',
|
|
10
|
+
detail: 'The request has no session',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
this.name = 'UnauthenticatedError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** A session whose user has not turned two-factor on: 403, the caller sets it up. */
|
|
17
|
+
export class TwoFactorRequiredError extends HTTPException {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(403, {
|
|
20
|
+
message: 'Two-factor authentication required',
|
|
21
|
+
cause: {
|
|
22
|
+
code: 'auth/two-factor-required',
|
|
23
|
+
detail: 'The user has not turned on two-factor authentication',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
this.name = 'TwoFactorRequiredError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Refuses a request without a session, and, with `twoFactor: true`, a session
|
|
31
|
+
* whose user has not turned two-factor on. A request that passes has the
|
|
32
|
+
* session on `c.var.session`. An error of `getSession` (the database is down)
|
|
33
|
+
* reaches the app as it is.
|
|
34
|
+
*/
|
|
35
|
+
export function requireSession(auth, options) {
|
|
36
|
+
return createMiddleware(async (c, next) => {
|
|
37
|
+
const session = await auth.api.getSession({ headers: c.req.raw.headers });
|
|
38
|
+
if (session === null)
|
|
39
|
+
throw new UnauthenticatedError();
|
|
40
|
+
// better-auth gives no session to a user who turned two-factor on and has
|
|
41
|
+
// not entered the code yet, so only a user who never turned it on is left.
|
|
42
|
+
if (options?.twoFactor === true && !hasTwoFactor(session.user))
|
|
43
|
+
throw new TwoFactorRequiredError();
|
|
44
|
+
c.set('session', session);
|
|
45
|
+
await next();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// The same check as src/react-router.ts: a copy of one line (root ADR 0001
|
|
49
|
+
// keeps tiny helpers copied); change both together.
|
|
50
|
+
function hasTwoFactor(user) {
|
|
51
|
+
return 'twoFactorEnabled' in user && user.twoFactorEnabled === true;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=hono.js.map
|
package/dist/hono.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAqBpD,6DAA6D;AAC7D,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAMrD;QACE,KAAK,CAAC,GAAG,EAAE;YACT,OAAO,EAAE,yBAAyB;YAClC,KAAK,EAAE;gBACL,IAAI,EAAE,sBAAsB;gBAC5B,MAAM,EAAE,4BAA4B;aACrC;SACF,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,qFAAqF;AACrF,MAAM,OAAO,sBAAuB,SAAQ,aAAa;IAMvD;QACE,KAAK,CAAC,GAAG,EAAE;YACT,OAAO,EAAE,oCAAoC;YAC7C,KAAK,EAAE;gBACL,IAAI,EAAE,0BAA0B;gBAChC,MAAM,EAAE,sDAAsD;aAC/D;SACF,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAsB,EACtB,OAAkC;IAElC,OAAO,gBAAgB,CAAgC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QACvE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1E,IAAI,OAAO,KAAK,IAAI;YAAE,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACvD,0EAA0E;QAC1E,2EAA2E;QAC3E,IAAI,OAAO,EAAE,SAAS,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;YAC5D,MAAM,IAAI,sBAAsB,EAAE,CAAC;QACrC,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC1B,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAED,2EAA2E;AAC3E,oDAAoD;AACpD,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,kBAAkB,IAAI,IAAI,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The member of a better-auth client that the guard calls. A
|
|
3
|
+
* `createAuthClient({ … })` client is one, with its default `{ data, error }`
|
|
4
|
+
* results. A client made with `fetchOptions: { throw: true }` gives the
|
|
5
|
+
* session itself and is not one.
|
|
6
|
+
*/
|
|
7
|
+
export interface SessionClient<S> {
|
|
8
|
+
getSession(): Promise<{
|
|
9
|
+
data: S | null;
|
|
10
|
+
error: {
|
|
11
|
+
status: number;
|
|
12
|
+
} | null;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `twoFactorSetup` exists only when the session's user has
|
|
17
|
+
* `twoFactorEnabled`, which better-auth's two-factor plugin adds.
|
|
18
|
+
*/
|
|
19
|
+
export type RequireSessionOptions<S extends {
|
|
20
|
+
user: object;
|
|
21
|
+
}> = {
|
|
22
|
+
readonly signIn: string;
|
|
23
|
+
} & ('twoFactorEnabled' extends keyof S['user'] ? {
|
|
24
|
+
readonly twoFactorSetup?: string;
|
|
25
|
+
} : {
|
|
26
|
+
readonly twoFactorSetup?: never;
|
|
27
|
+
});
|
|
28
|
+
export interface SafeRedirectOptions {
|
|
29
|
+
readonly origin: string;
|
|
30
|
+
readonly fallback: string;
|
|
31
|
+
readonly exclude?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/** The query parameter that carries the return path. */
|
|
34
|
+
export declare const REDIRECT_TO = "redirectTo";
|
|
35
|
+
/**
|
|
36
|
+
* The browser could not read the session: the network failed, or better-auth
|
|
37
|
+
* answered with an error. It is not "signed out"; the caller tries again.
|
|
38
|
+
*/
|
|
39
|
+
export declare class AuthenticationUnavailableError extends Error {
|
|
40
|
+
constructor(options: {
|
|
41
|
+
cause: unknown;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The session of a protected page's loader. A visitor without one is sent to
|
|
46
|
+
* `signIn` with the page as the return path, and, with `twoFactorSetup`, a
|
|
47
|
+
* user who never turned two-factor on is sent there. Both throw React
|
|
48
|
+
* Router's `replace()`, so the back button skips the page that redirected.
|
|
49
|
+
*/
|
|
50
|
+
export declare function requireSession<S extends {
|
|
51
|
+
user: object;
|
|
52
|
+
}>(client: SessionClient<S>, request: Request, options: RequireSessionOptions<S>): Promise<S>;
|
|
53
|
+
/**
|
|
54
|
+
* `to` when it is a path on `origin` that is not in `exclude`, otherwise
|
|
55
|
+
* `fallback`. The answer is the parsed path, query and hash, never the raw
|
|
56
|
+
* string, so a character that the URL parser drops cannot turn it into
|
|
57
|
+
* another site.
|
|
58
|
+
*/
|
|
59
|
+
export declare function safeRedirect(to: string | null | undefined, options: SafeRedirectOptions): string;
|
|
60
|
+
//# sourceMappingURL=react-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-router.d.ts","sourceRoot":"","sources":["../src/react-router.ts"],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AI,GAAG,SAAS,EAC7B,OAAO,EAAE,mBAAmB,GAC3B,MAAM,CAIR"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { replace } from 'react-router';
|
|
2
|
+
/** The query parameter that carries the return path. */
|
|
3
|
+
export const REDIRECT_TO = 'redirectTo';
|
|
4
|
+
const MAX_RETURN_PATH = 2048;
|
|
5
|
+
/**
|
|
6
|
+
* The browser could not read the session: the network failed, or better-auth
|
|
7
|
+
* answered with an error. It is not "signed out"; the caller tries again.
|
|
8
|
+
*/
|
|
9
|
+
export class AuthenticationUnavailableError extends Error {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super('The session could not be read', options);
|
|
12
|
+
this.name = 'AuthenticationUnavailableError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The session of a protected page's loader. A visitor without one is sent to
|
|
17
|
+
* `signIn` with the page as the return path, and, with `twoFactorSetup`, a
|
|
18
|
+
* user who never turned two-factor on is sent there. Both throw React
|
|
19
|
+
* Router's `replace()`, so the back button skips the page that redirected.
|
|
20
|
+
*/
|
|
21
|
+
export async function requireSession(client, request, options) {
|
|
22
|
+
let result;
|
|
23
|
+
try {
|
|
24
|
+
result = await client.getSession();
|
|
25
|
+
}
|
|
26
|
+
catch (cause) {
|
|
27
|
+
throw new AuthenticationUnavailableError({ cause });
|
|
28
|
+
}
|
|
29
|
+
if (result.error !== null)
|
|
30
|
+
throw new AuthenticationUnavailableError({ cause: result.error });
|
|
31
|
+
const url = new URL(request.url);
|
|
32
|
+
const authPages = [options.signIn, options.twoFactorSetup]
|
|
33
|
+
.filter((page) => page !== undefined)
|
|
34
|
+
.map((page) => new URL(page, url).pathname);
|
|
35
|
+
if (result.data === null)
|
|
36
|
+
throw replace(withReturnPath(options.signIn, url, authPages));
|
|
37
|
+
const setup = options.twoFactorSetup;
|
|
38
|
+
// The setup page itself passes, or it would redirect to itself forever.
|
|
39
|
+
if (setup !== undefined &&
|
|
40
|
+
!hasTwoFactor(result.data.user) &&
|
|
41
|
+
url.pathname !== new URL(setup, url).pathname)
|
|
42
|
+
throw replace(withReturnPath(setup, url, authPages));
|
|
43
|
+
return result.data;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `to` when it is a path on `origin` that is not in `exclude`, otherwise
|
|
47
|
+
* `fallback`. The answer is the parsed path, query and hash, never the raw
|
|
48
|
+
* string, so a character that the URL parser drops cannot turn it into
|
|
49
|
+
* another site.
|
|
50
|
+
*/
|
|
51
|
+
export function safeRedirect(to, options) {
|
|
52
|
+
return (safePath(to, options.origin, options.exclude ?? []) ?? options.fallback);
|
|
53
|
+
}
|
|
54
|
+
function safePath(to, origin, exclude) {
|
|
55
|
+
if (to === null || to === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
if (!isLocal(to) || to.length > MAX_RETURN_PATH)
|
|
58
|
+
return undefined;
|
|
59
|
+
const base = new URL(origin);
|
|
60
|
+
const parsed = URL.parse(to, base);
|
|
61
|
+
if (parsed === null || parsed.origin !== base.origin)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (exclude.includes(parsed.pathname))
|
|
64
|
+
return undefined;
|
|
65
|
+
const path = parsed.pathname + parsed.search + parsed.hash;
|
|
66
|
+
// The parser folds `/.//evil.example` into `//evil.example`.
|
|
67
|
+
return isLocal(path) ? path : undefined;
|
|
68
|
+
}
|
|
69
|
+
/** A leading `/`, not `//` or `/\`, as ASP.NET's `Url.IsLocalUrl`. */
|
|
70
|
+
function isLocal(path) {
|
|
71
|
+
return (path.startsWith('/') && !path.startsWith('//') && !path.startsWith('/\\'));
|
|
72
|
+
}
|
|
73
|
+
function withReturnPath(page, url, authPages) {
|
|
74
|
+
// On an auth page, the page's own return path goes on, so no page sends a
|
|
75
|
+
// visitor back to sign in.
|
|
76
|
+
const returnPath = authPages.includes(url.pathname)
|
|
77
|
+
? safePath(url.searchParams.get(REDIRECT_TO), url.origin, authPages)
|
|
78
|
+
: url.pathname + url.search;
|
|
79
|
+
if (returnPath === undefined ||
|
|
80
|
+
!isLocal(returnPath) ||
|
|
81
|
+
returnPath.length > MAX_RETURN_PATH)
|
|
82
|
+
return page;
|
|
83
|
+
const separator = page.includes('?') ? '&' : '?';
|
|
84
|
+
return `${page}${separator}${new URLSearchParams({ [REDIRECT_TO]: returnPath })}`;
|
|
85
|
+
}
|
|
86
|
+
// The same check as src/hono.ts: a copy of one line (root ADR 0001 keeps tiny
|
|
87
|
+
// helpers copied); change both together.
|
|
88
|
+
function hasTwoFactor(user) {
|
|
89
|
+
return 'twoFactorEnabled' in user && user.twoFactorEnabled === true;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=react-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-router.js","sourceRoot":"","sources":["../src/react-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA4BvC,wDAAwD;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAC;AAExC,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B;;;GAGG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACvD,YAAY,OAA2B;QACrC,KAAK,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAwB,EACxB,OAAgB,EAChB,OAAiC;IAEjC,IAAI,MAA2D,CAAC;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,8BAA8B,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI;QACvB,MAAM,IAAI,8BAA8B,CAAC,E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,MAAM,CAAC;IAC9B,IACE,UAAU,KAAK,SAAS;QACxB,CAAC,OAAO,CAAC,UAAU,CAAC;QACpB,UAAU,CAAC,MAAM,GAAG,eAAe;QAEnC,OAAO,IAAI,CAAC;IACd,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACjD,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,eAAe,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;AACpF,CAAC;AAED,8EAA8E;AAC9E,yCAAyC;AACzC,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,kBAAkB,IAAI,IAAI,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/authentication",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.36",
|
|
4
|
+
"description": "The better-auth session at the edges of an app: a Hono middleware that refuses a request without a session or without two-factor, and a React Router loader guard that sends a visitor to sign in and back on a safe return path.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/JanuaryLabs/zukhruf",
|
|
9
|
+
"directory": "packages/authentication"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/JanuaryLabs/zukhruf/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/JanuaryLabs/zukhruf/tree/main/packages/authentication#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"authentication",
|
|
17
|
+
"better-auth",
|
|
18
|
+
"hono",
|
|
19
|
+
"react-router",
|
|
20
|
+
"session",
|
|
21
|
+
"two-factor"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
"./package.json": "./package.json",
|
|
26
|
+
"./hono": {
|
|
27
|
+
"@zukhruf/source": "./src/hono.ts",
|
|
28
|
+
"types": "./dist/hono.d.ts",
|
|
29
|
+
"import": "./dist/hono.js",
|
|
30
|
+
"default": "./dist/hono.js"
|
|
31
|
+
},
|
|
32
|
+
"./react-router": {
|
|
33
|
+
"@zukhruf/source": "./src/react-router.ts",
|
|
34
|
+
"types": "./dist/react-router.d.ts",
|
|
35
|
+
"import": "./dist/react-router.js",
|
|
36
|
+
"default": "./dist/react-router.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"!dist/spec/**",
|
|
42
|
+
"!**/*.tsbuildinfo",
|
|
43
|
+
"!**/*.test.*"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"hono": "^4.13.19",
|
|
50
|
+
"react-router": "^8.5.2"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"hono": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"react-router": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"better-auth": "1.7.26",
|
|
62
|
+
"hono": "^4.13.19",
|
|
63
|
+
"react-router": "^8.5.2"
|
|
64
|
+
}
|
|
65
|
+
}
|