@nexusts/auth 0.7.0
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/README.md +45 -0
- package/dist/index.js +502 -0
- package/dist/index.js.map +15 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @nexusts/auth
|
|
2
|
+
|
|
3
|
+
> **NexusTS** — Bun-native fullstack framework
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
Authentication via better-auth integration.
|
|
8
|
+
|
|
9
|
+
Provides authentication via better-auth. Brings the standard adapter so better-auth's API stays consistent with the rest of NexusTS (DI / decorator model). Type-safe users via @CurrentUser, sessions integrated with the framework's session module.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
This module is part of the NexusTS monorepo. Each module is published as its own npm package under the `@nexusts/` scope.
|
|
14
|
+
|
|
15
|
+
Most apps start with just the core:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @nexusts/core reflect-metadata zod hono
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then add this module only if you need it:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun add @nexusts/auth
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Peer dependencies
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add better-auth
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Required by this module. Without them the module loads but its public methods throw a clear error pointing to this install command on first call.
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { /* public API */ } from "@nexusts/auth";
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
See the [user guide](../../docs/user-guide/auth.md) and the [example app](../../examples/) for a working demo.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT — see the root [LICENSE](../../LICENSE).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
5
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
6
|
+
else
|
|
7
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
8
|
+
if (d = decorators[i])
|
|
9
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11
|
+
};
|
|
12
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
13
|
+
var __legacyMetadataTS = (k, v) => {
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
15
|
+
return Reflect.metadata(k, v);
|
|
16
|
+
};
|
|
17
|
+
var __require = import.meta.require;
|
|
18
|
+
// packages/auth/src/auth.ts
|
|
19
|
+
import { betterAuth } from "better-auth";
|
|
20
|
+
function createAuth(config = {}) {
|
|
21
|
+
const secret = config.secret ?? process.env["BETTER_AUTH_SECRET"];
|
|
22
|
+
const baseURL = config.baseUrl ?? process.env["BETTER_AUTH_URL"];
|
|
23
|
+
if (!secret) {
|
|
24
|
+
throw new Error("[nexus/auth] BETTER_AUTH_SECRET is required. " + "Generate one with `openssl rand -base64 32` and add it to .env.");
|
|
25
|
+
}
|
|
26
|
+
if (!baseURL) {
|
|
27
|
+
throw new Error("[nexus/auth] BETTER_AUTH_URL is required (e.g. http://localhost:3000).");
|
|
28
|
+
}
|
|
29
|
+
const plugins = [];
|
|
30
|
+
if (config.jwt?.enabled) {
|
|
31
|
+
const { jwt } = __require("better-auth/plugins");
|
|
32
|
+
plugins.push(jwt({
|
|
33
|
+
jwks: {
|
|
34
|
+
path: config.jwt.jwksPath ?? "/api/auth/jwks"
|
|
35
|
+
},
|
|
36
|
+
issuer: config.jwt.issuer ?? baseURL,
|
|
37
|
+
audience: config.jwt.audience ?? baseURL,
|
|
38
|
+
expiresIn: config.jwt.expiresIn ?? 60 * 15
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
if (config.passkey?.enabled) {
|
|
42
|
+
const { passkey } = __require("better-auth/plugins");
|
|
43
|
+
plugins.push(passkey({
|
|
44
|
+
rpName: config.passkey.rpName,
|
|
45
|
+
rpID: config.passkey.rpId,
|
|
46
|
+
origin: config.passkey.origin
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
return betterAuth({
|
|
50
|
+
secret,
|
|
51
|
+
baseURL,
|
|
52
|
+
basePath: config.basePath ?? "/api/auth",
|
|
53
|
+
emailAndPassword: {
|
|
54
|
+
enabled: config.emailAndPassword?.enabled ?? true,
|
|
55
|
+
requireEmailVerification: config.emailAndPassword?.requireEmailVerification ?? false,
|
|
56
|
+
minPasswordLength: config.emailAndPassword?.minPasswordLength ?? 8,
|
|
57
|
+
maxPasswordLength: config.emailAndPassword?.maxPasswordLength ?? 128
|
|
58
|
+
},
|
|
59
|
+
session: {
|
|
60
|
+
expiresIn: config.sessionExpiresInSeconds ?? 60 * 60 * 24 * 7
|
|
61
|
+
},
|
|
62
|
+
socialProviders: config.socialProviders,
|
|
63
|
+
advanced: {
|
|
64
|
+
cookies: {
|
|
65
|
+
sessionToken: {
|
|
66
|
+
attributes: {
|
|
67
|
+
sameSite: config.cookieSameSite ?? "lax",
|
|
68
|
+
secure: config.cookieSecure ?? process.env["NODE_ENV"] === "production",
|
|
69
|
+
...config.cookieDomain ? { domain: config.cookieDomain } : {}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
crossSubDomainCookies: config.crossSubDomainCookies?.enabled ? {
|
|
74
|
+
enabled: true,
|
|
75
|
+
domain: config.crossSubDomainCookies.domain
|
|
76
|
+
} : undefined
|
|
77
|
+
},
|
|
78
|
+
plugins
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// packages/auth/src/auth.service.ts
|
|
82
|
+
import { Inject, Injectable } from "@nexusts/core/decorators/index.js";
|
|
83
|
+
class AuthService {
|
|
84
|
+
config;
|
|
85
|
+
static TOKEN = Symbol.for("nexus:AuthService");
|
|
86
|
+
instance;
|
|
87
|
+
#sessionService = null;
|
|
88
|
+
constructor(config) {
|
|
89
|
+
this.config = config;
|
|
90
|
+
this.instance = createAuth(this.config);
|
|
91
|
+
}
|
|
92
|
+
bindSession(sessionService) {
|
|
93
|
+
this.#sessionService = sessionService;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
hasSessionBinding() {
|
|
97
|
+
return this.#sessionService !== null;
|
|
98
|
+
}
|
|
99
|
+
async getSession(input) {
|
|
100
|
+
if (this.#sessionService) {
|
|
101
|
+
const cookieName = this.#sessionService.cookieName;
|
|
102
|
+
if (cookieName) {
|
|
103
|
+
const cookieHeader = input.headers.get("cookie") ?? "";
|
|
104
|
+
const value = parseCookie(cookieHeader, cookieName);
|
|
105
|
+
if (value) {
|
|
106
|
+
const decoded = this.#sessionService.decodeCookie(value);
|
|
107
|
+
if (decoded?.userId) {
|
|
108
|
+
const fromBetterAuth = await this.instance.api.getSession({
|
|
109
|
+
headers: input.headers
|
|
110
|
+
});
|
|
111
|
+
if (fromBetterAuth?.user) {
|
|
112
|
+
return fromBetterAuth;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const result = await this.instance.api.getSession({
|
|
119
|
+
headers: input.headers
|
|
120
|
+
});
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
async getRawSession(input) {
|
|
124
|
+
if (!this.#sessionService)
|
|
125
|
+
return null;
|
|
126
|
+
const cookieName = this.#sessionService.cookieName;
|
|
127
|
+
if (!cookieName)
|
|
128
|
+
return null;
|
|
129
|
+
const cookieHeader = input.headers.get("cookie") ?? "";
|
|
130
|
+
const value = parseCookie(cookieHeader, cookieName);
|
|
131
|
+
if (!value)
|
|
132
|
+
return null;
|
|
133
|
+
return this.#sessionService.decodeCookie(value);
|
|
134
|
+
}
|
|
135
|
+
async signUp(input) {
|
|
136
|
+
return this.instance.api.signUpEmail({
|
|
137
|
+
body: input
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async signIn(input) {
|
|
141
|
+
return this.instance.api.signInEmail({
|
|
142
|
+
body: input
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async signOut(input) {
|
|
146
|
+
return this.instance.api.signOut({
|
|
147
|
+
headers: input.headers
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async getOAuthUrl(input) {
|
|
151
|
+
return this.instance.api.signInSocial({
|
|
152
|
+
body: input
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async handleOAuthCallback(input) {
|
|
156
|
+
return this.instance.api.signInSocial({
|
|
157
|
+
headers: input.headers,
|
|
158
|
+
query: input.query,
|
|
159
|
+
body: {}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async issueJwt(input) {
|
|
163
|
+
const api = this.instance.api;
|
|
164
|
+
if (!api.signJWT) {
|
|
165
|
+
throw new Error("[nexus/auth] JWT plugin not enabled. Set `auth.jwt.enabled: true` in nx.config.ts.");
|
|
166
|
+
}
|
|
167
|
+
return api.signJWT({ body: { userId: input.userId } });
|
|
168
|
+
}
|
|
169
|
+
async registerPasskey(input) {
|
|
170
|
+
const api = this.instance.api;
|
|
171
|
+
if (!api.passkey) {
|
|
172
|
+
throw new Error("[nexus/auth] Passkey plugin not enabled. Set `auth.passkey.enabled: true` in nx.config.ts.");
|
|
173
|
+
}
|
|
174
|
+
return api.passkey.register({ headers: input.headers });
|
|
175
|
+
}
|
|
176
|
+
async authenticatePasskey(input) {
|
|
177
|
+
const api = this.instance.api;
|
|
178
|
+
if (!api.passkey) {
|
|
179
|
+
throw new Error("[nexus/auth] Passkey plugin not enabled.");
|
|
180
|
+
}
|
|
181
|
+
return api.passkey.authenticate({ headers: input.headers, body: input.body });
|
|
182
|
+
}
|
|
183
|
+
redirect(to, status = 302) {
|
|
184
|
+
return new Response(null, { status, headers: { Location: to } });
|
|
185
|
+
}
|
|
186
|
+
toContextVariables(session) {
|
|
187
|
+
if (!session)
|
|
188
|
+
return { user: null, session: null };
|
|
189
|
+
return { user: session.user, session: session.session };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
AuthService = __legacyDecorateClassTS([
|
|
193
|
+
Injectable(),
|
|
194
|
+
__legacyDecorateParamTS(0, Inject("AUTH_CONFIG")),
|
|
195
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
196
|
+
typeof AuthConfig === "undefined" ? Object : AuthConfig
|
|
197
|
+
])
|
|
198
|
+
], AuthService);
|
|
199
|
+
function parseCookie(cookieHeader, name) {
|
|
200
|
+
if (!cookieHeader)
|
|
201
|
+
return null;
|
|
202
|
+
const parts = cookieHeader.split(";");
|
|
203
|
+
for (const part of parts) {
|
|
204
|
+
const eq = part.indexOf("=");
|
|
205
|
+
if (eq < 0)
|
|
206
|
+
continue;
|
|
207
|
+
const k = part.slice(0, eq).trim();
|
|
208
|
+
if (k === name) {
|
|
209
|
+
return decodeURIComponent(part.slice(eq + 1).trim());
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
// packages/auth/src/auth.controller.ts
|
|
215
|
+
import {
|
|
216
|
+
Body,
|
|
217
|
+
Controller,
|
|
218
|
+
Get,
|
|
219
|
+
Inject as Inject2,
|
|
220
|
+
Post,
|
|
221
|
+
Req,
|
|
222
|
+
Res
|
|
223
|
+
} from "@nexusts/core/decorators/index.js";
|
|
224
|
+
class AuthController {
|
|
225
|
+
auth;
|
|
226
|
+
constructor(auth) {
|
|
227
|
+
this.auth = auth;
|
|
228
|
+
}
|
|
229
|
+
async session(c) {
|
|
230
|
+
const session = await this.auth.getSession({
|
|
231
|
+
headers: c.req.raw.headers
|
|
232
|
+
});
|
|
233
|
+
return c.json(session ?? { user: null, session: null });
|
|
234
|
+
}
|
|
235
|
+
async signUpEmail(c, body) {
|
|
236
|
+
const result = await this.auth.signUp(body);
|
|
237
|
+
return c.json(result, 201);
|
|
238
|
+
}
|
|
239
|
+
async signInEmail(c, body) {
|
|
240
|
+
const result = await this.auth.signIn(body);
|
|
241
|
+
return c.json(result);
|
|
242
|
+
}
|
|
243
|
+
async signOut(c, _res) {
|
|
244
|
+
await this.auth.signOut({ headers: c.req.raw.headers });
|
|
245
|
+
return c.json({ ok: true });
|
|
246
|
+
}
|
|
247
|
+
async socialSignIn(c, _body) {
|
|
248
|
+
const provider = c.req.param("provider") ?? "";
|
|
249
|
+
const callbackURL = c.req.query("callbackURL") ?? "/";
|
|
250
|
+
const result = await this.auth.getOAuthUrl({ provider, callbackURL });
|
|
251
|
+
return c.json(result);
|
|
252
|
+
}
|
|
253
|
+
async oauthCallback(c) {
|
|
254
|
+
const result = await this.auth.handleOAuthCallback({
|
|
255
|
+
headers: c.req.raw.headers,
|
|
256
|
+
query: c.req.query()
|
|
257
|
+
});
|
|
258
|
+
return c.json(result);
|
|
259
|
+
}
|
|
260
|
+
async issueJwt(c) {
|
|
261
|
+
const session = await this.auth.getSession({
|
|
262
|
+
headers: c.req.raw.headers
|
|
263
|
+
});
|
|
264
|
+
if (!session)
|
|
265
|
+
return c.json({ error: "Unauthorized" }, 401);
|
|
266
|
+
const token = await this.auth.issueJwt({ userId: session.user.id });
|
|
267
|
+
return c.json(token);
|
|
268
|
+
}
|
|
269
|
+
async passkeyRegister(c) {
|
|
270
|
+
const result = await this.auth.registerPasskey({
|
|
271
|
+
headers: c.req.raw.headers
|
|
272
|
+
});
|
|
273
|
+
return c.json(result);
|
|
274
|
+
}
|
|
275
|
+
async passkeyAuthenticate(c, body) {
|
|
276
|
+
const result = await this.auth.authenticatePasskey({
|
|
277
|
+
headers: c.req.raw.headers,
|
|
278
|
+
body
|
|
279
|
+
});
|
|
280
|
+
return c.json(result);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
__legacyDecorateClassTS([
|
|
284
|
+
Get("/session"),
|
|
285
|
+
__legacyDecorateParamTS(0, Req()),
|
|
286
|
+
__legacyMetadataTS("design:type", Function),
|
|
287
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
288
|
+
typeof Context === "undefined" ? Object : Context
|
|
289
|
+
]),
|
|
290
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
291
|
+
], AuthController.prototype, "session", null);
|
|
292
|
+
__legacyDecorateClassTS([
|
|
293
|
+
Post("/sign-up/email"),
|
|
294
|
+
__legacyDecorateParamTS(0, Req()),
|
|
295
|
+
__legacyDecorateParamTS(1, Body()),
|
|
296
|
+
__legacyMetadataTS("design:type", Function),
|
|
297
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
298
|
+
typeof Context === "undefined" ? Object : Context,
|
|
299
|
+
Object
|
|
300
|
+
]),
|
|
301
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
302
|
+
], AuthController.prototype, "signUpEmail", null);
|
|
303
|
+
__legacyDecorateClassTS([
|
|
304
|
+
Post("/sign-in/email"),
|
|
305
|
+
__legacyDecorateParamTS(0, Req()),
|
|
306
|
+
__legacyDecorateParamTS(1, Body()),
|
|
307
|
+
__legacyMetadataTS("design:type", Function),
|
|
308
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
309
|
+
typeof Context === "undefined" ? Object : Context,
|
|
310
|
+
Object
|
|
311
|
+
]),
|
|
312
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
313
|
+
], AuthController.prototype, "signInEmail", null);
|
|
314
|
+
__legacyDecorateClassTS([
|
|
315
|
+
Post("/sign-out"),
|
|
316
|
+
__legacyDecorateParamTS(0, Req()),
|
|
317
|
+
__legacyDecorateParamTS(1, Res()),
|
|
318
|
+
__legacyMetadataTS("design:type", Function),
|
|
319
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
320
|
+
typeof Context === "undefined" ? Object : Context,
|
|
321
|
+
typeof Response === "undefined" ? Object : Response
|
|
322
|
+
]),
|
|
323
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
324
|
+
], AuthController.prototype, "signOut", null);
|
|
325
|
+
__legacyDecorateClassTS([
|
|
326
|
+
Get("/sign-in/:provider"),
|
|
327
|
+
__legacyDecorateParamTS(0, Req()),
|
|
328
|
+
__legacyDecorateParamTS(1, Body()),
|
|
329
|
+
__legacyMetadataTS("design:type", Function),
|
|
330
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
331
|
+
typeof Context === "undefined" ? Object : Context,
|
|
332
|
+
undefined
|
|
333
|
+
]),
|
|
334
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
335
|
+
], AuthController.prototype, "socialSignIn", null);
|
|
336
|
+
__legacyDecorateClassTS([
|
|
337
|
+
Get("/callback/:provider"),
|
|
338
|
+
__legacyDecorateParamTS(0, Req()),
|
|
339
|
+
__legacyMetadataTS("design:type", Function),
|
|
340
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
341
|
+
typeof Context === "undefined" ? Object : Context
|
|
342
|
+
]),
|
|
343
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
344
|
+
], AuthController.prototype, "oauthCallback", null);
|
|
345
|
+
__legacyDecorateClassTS([
|
|
346
|
+
Post("/jwt"),
|
|
347
|
+
__legacyDecorateParamTS(0, Req()),
|
|
348
|
+
__legacyMetadataTS("design:type", Function),
|
|
349
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
350
|
+
typeof Context === "undefined" ? Object : Context
|
|
351
|
+
]),
|
|
352
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
353
|
+
], AuthController.prototype, "issueJwt", null);
|
|
354
|
+
__legacyDecorateClassTS([
|
|
355
|
+
Post("/passkey/register"),
|
|
356
|
+
__legacyDecorateParamTS(0, Req()),
|
|
357
|
+
__legacyMetadataTS("design:type", Function),
|
|
358
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
359
|
+
typeof Context === "undefined" ? Object : Context
|
|
360
|
+
]),
|
|
361
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
362
|
+
], AuthController.prototype, "passkeyRegister", null);
|
|
363
|
+
__legacyDecorateClassTS([
|
|
364
|
+
Post("/passkey/authenticate"),
|
|
365
|
+
__legacyDecorateParamTS(0, Req()),
|
|
366
|
+
__legacyDecorateParamTS(1, Body()),
|
|
367
|
+
__legacyMetadataTS("design:type", Function),
|
|
368
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
369
|
+
typeof Context === "undefined" ? Object : Context,
|
|
370
|
+
Object
|
|
371
|
+
]),
|
|
372
|
+
__legacyMetadataTS("design:returntype", Promise)
|
|
373
|
+
], AuthController.prototype, "passkeyAuthenticate", null);
|
|
374
|
+
AuthController = __legacyDecorateClassTS([
|
|
375
|
+
Controller("/api/auth"),
|
|
376
|
+
__legacyDecorateParamTS(0, Inject2(AuthService.TOKEN)),
|
|
377
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
378
|
+
typeof AuthService === "undefined" ? Object : AuthService
|
|
379
|
+
])
|
|
380
|
+
], AuthController);
|
|
381
|
+
// packages/auth/src/auth.module.ts
|
|
382
|
+
import"reflect-metadata";
|
|
383
|
+
import { Module } from "@nexusts/core/decorators/module.js";
|
|
384
|
+
class AuthModule {
|
|
385
|
+
static forRoot(config) {
|
|
386
|
+
class ConfiguredAuthModule {
|
|
387
|
+
}
|
|
388
|
+
ConfiguredAuthModule = __legacyDecorateClassTS([
|
|
389
|
+
Module({
|
|
390
|
+
controllers: [AuthController],
|
|
391
|
+
providers: [
|
|
392
|
+
AuthService,
|
|
393
|
+
{ provide: AuthService.TOKEN, useExisting: AuthService },
|
|
394
|
+
{ provide: "AUTH_CONFIG", useValue: config }
|
|
395
|
+
],
|
|
396
|
+
exports: [AuthService, AuthService.TOKEN]
|
|
397
|
+
})
|
|
398
|
+
], ConfiguredAuthModule);
|
|
399
|
+
Object.defineProperty(ConfiguredAuthModule, "name", {
|
|
400
|
+
value: "ConfiguredAuthModule"
|
|
401
|
+
});
|
|
402
|
+
return ConfiguredAuthModule;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
AuthModule = __legacyDecorateClassTS([
|
|
406
|
+
Module({
|
|
407
|
+
controllers: [AuthController],
|
|
408
|
+
providers: [
|
|
409
|
+
AuthService,
|
|
410
|
+
{ provide: AuthService.TOKEN, useExisting: AuthService }
|
|
411
|
+
],
|
|
412
|
+
exports: [AuthService, AuthService.TOKEN]
|
|
413
|
+
})
|
|
414
|
+
], AuthModule);
|
|
415
|
+
// packages/auth/src/middleware.ts
|
|
416
|
+
function authMiddleware(auth, options = {}) {
|
|
417
|
+
const {
|
|
418
|
+
mode = "optional",
|
|
419
|
+
scope,
|
|
420
|
+
protectedPaths,
|
|
421
|
+
ignoredPaths,
|
|
422
|
+
onUnauthenticated = defaultUnauthenticated,
|
|
423
|
+
onForbidden = defaultForbidden
|
|
424
|
+
} = options;
|
|
425
|
+
const ignored = toMatcher(ignoredPaths);
|
|
426
|
+
const protected_ = mode === "scoped" ? toMatcher(scope ?? protectedPaths ?? /^\/.+/) : null;
|
|
427
|
+
return async (c, next) => {
|
|
428
|
+
const path = c.req.path;
|
|
429
|
+
if (ignored?.test(path)) {
|
|
430
|
+
return next();
|
|
431
|
+
}
|
|
432
|
+
const session = await auth.api.getSession({
|
|
433
|
+
headers: c.req.raw.headers
|
|
434
|
+
});
|
|
435
|
+
if (session) {
|
|
436
|
+
c.set("user", session.user);
|
|
437
|
+
c.set("session", session.session);
|
|
438
|
+
} else {
|
|
439
|
+
c.set("user", null);
|
|
440
|
+
c.set("session", null);
|
|
441
|
+
}
|
|
442
|
+
if (mode === "required" || protected_?.test(path) && session === null) {
|
|
443
|
+
if (session === null)
|
|
444
|
+
return onUnauthenticated(c);
|
|
445
|
+
}
|
|
446
|
+
return next();
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function toMatcher(input) {
|
|
450
|
+
if (!input)
|
|
451
|
+
return null;
|
|
452
|
+
if (Array.isArray(input)) {
|
|
453
|
+
return new RegExp(input.map((r) => `(?:${r.source})`).join("|"));
|
|
454
|
+
}
|
|
455
|
+
return input;
|
|
456
|
+
}
|
|
457
|
+
function defaultUnauthenticated(c) {
|
|
458
|
+
return c.json({ error: "Unauthorized", message: "Authentication required." }, 401);
|
|
459
|
+
}
|
|
460
|
+
function defaultForbidden(c) {
|
|
461
|
+
return c.json({ error: "Forbidden", message: "Insufficient permissions." }, 403);
|
|
462
|
+
}
|
|
463
|
+
function authHandler(auth) {
|
|
464
|
+
return async (c) => auth.handler(c.req.raw);
|
|
465
|
+
}
|
|
466
|
+
// packages/auth/src/decorators/current-user.ts
|
|
467
|
+
import"reflect-metadata";
|
|
468
|
+
import { createParamDecorator } from "@nexusts/core/src/decorators/params.js";
|
|
469
|
+
import { PARAM_TYPES } from "@nexusts/core/src/constants.js";
|
|
470
|
+
function CurrentUser(options = {}) {
|
|
471
|
+
return createParamDecorator(PARAM_TYPES.USER, options);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
class UnauthenticatedError extends Error {
|
|
475
|
+
status = 401;
|
|
476
|
+
constructor(message = "Authentication required.") {
|
|
477
|
+
super(message);
|
|
478
|
+
this.name = "UnauthenticatedError";
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
class ForbiddenError extends Error {
|
|
483
|
+
status = 403;
|
|
484
|
+
constructor(message = "Insufficient permissions.") {
|
|
485
|
+
super(message);
|
|
486
|
+
this.name = "ForbiddenError";
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
export {
|
|
490
|
+
createAuth,
|
|
491
|
+
authMiddleware,
|
|
492
|
+
authHandler,
|
|
493
|
+
UnauthenticatedError,
|
|
494
|
+
ForbiddenError,
|
|
495
|
+
CurrentUser,
|
|
496
|
+
AuthService,
|
|
497
|
+
AuthModule,
|
|
498
|
+
AuthController
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
//# debugId=5736524FC5C13DE864756E2164756E21
|
|
502
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/auth.ts", "../src/auth.service.ts", "../src/auth.controller.ts", "../src/auth.module.ts", "../src/middleware.ts", "../src/decorators/current-user.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * `createAuth()` — wrap better-auth's `betterAuth()` factory with\n * NexusTS-friendly defaults.\n *\n * This is the **only** place that talks to better-auth directly. Every\n * other NexusTS auth module consumes the resulting `Auth` instance via\n * DI or the registered token.\n *\n * Why an adapter layer instead of calling `betterAuth()` directly?\n * 1. NexusTS users write `auth.config.ts`, not raw better-auth options.\n * The adapter translates between the two.\n * 2. Plugin selection (jwt, passkey) is toggled by boolean flags,\n * not by importing plugin objects.\n * 3. Cookie / CORS / cross-subdomain defaults match Hono's `cors()`\n * middleware so the two never conflict.\n *\n * Usage:\n * // src/auth/auth.ts\n * import { createAuth } from 'nexusjs/auth';\n * export const auth = createAuth({\n * basePath: '/api/auth',\n * emailAndPassword: { enabled: true },\n * socialProviders: {\n * github: {\n * clientId: process.env.GITHUB_CLIENT_ID!,\n * clientSecret: process.env.GITHUB_CLIENT_SECRET!,\n * },\n * },\n * });\n */\n\nimport { betterAuth } from \"better-auth\";\nimport type { AuthConfig } from \"./types.js\";\n\ntype BetterAuthInstance = ReturnType<typeof betterAuth>;\n\n/**\n * Create a better-auth instance with NexusTS-friendly defaults.\n *\n * @param config NexusTS-shaped config (see types.ts).\n * @returns A `better-auth` Auth instance.\n */\nexport function createAuth(config: AuthConfig = {}): BetterAuthInstance {\n\tconst secret = config.secret ?? process.env[\"BETTER_AUTH_SECRET\"];\n\tconst baseURL = config.baseUrl ?? process.env[\"BETTER_AUTH_URL\"];\n\n\tif (!secret) {\n\t\tthrow new Error(\n\t\t\t\"[nexus/auth] BETTER_AUTH_SECRET is required. \" +\n\t\t\t\t\"Generate one with `openssl rand -base64 32` and add it to .env.\",\n\t\t);\n\t}\n\tif (!baseURL) {\n\t\tthrow new Error(\n\t\t\t\"[nexus/auth] BETTER_AUTH_URL is required (e.g. http://localhost:3000).\",\n\t\t);\n\t}\n\n\tconst plugins: Array<unknown> = [];\n\n\t// JWT plugin — opt-in.\n\tif (config.jwt?.enabled) {\n\t\t// Lazy import so the plugin's transitive dependencies don't load\n\t\t// when the user hasn't asked for JWT.\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst { jwt } = require(\"better-auth/plugins\");\n\t\tplugins.push(\n\t\t\tjwt({\n\t\t\t\tjwks: {\n\t\t\t\t\tpath: config.jwt.jwksPath ?? \"/api/auth/jwks\",\n\t\t\t\t},\n\t\t\t\tissuer: config.jwt.issuer ?? baseURL,\n\t\t\t\taudience: config.jwt.audience ?? baseURL,\n\t\t\t\texpiresIn: config.jwt.expiresIn ?? 60 * 15,\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Passkey plugin — opt-in.\n\tif (config.passkey?.enabled) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst { passkey } = require(\"better-auth/plugins\");\n\t\tplugins.push(\n\t\t\tpasskey({\n\t\t\t\trpName: config.passkey.rpName,\n\t\t\t\trpID: config.passkey.rpId,\n\t\t\t\torigin: config.passkey.origin,\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn betterAuth({\n\t\tsecret,\n\t\tbaseURL,\n\t\tbasePath: config.basePath ?? \"/api/auth\",\n\t\temailAndPassword: {\n\t\t\tenabled: config.emailAndPassword?.enabled ?? true,\n\t\t\trequireEmailVerification:\n\t\t\t\tconfig.emailAndPassword?.requireEmailVerification ?? false,\n\t\t\tminPasswordLength: config.emailAndPassword?.minPasswordLength ?? 8,\n\t\t\tmaxPasswordLength: config.emailAndPassword?.maxPasswordLength ?? 128,\n\t\t},\n\t\tsession: {\n\t\t\texpiresIn: config.sessionExpiresInSeconds ?? 60 * 60 * 24 * 7, // 7 days\n\t\t},\n\t\tsocialProviders: config.socialProviders as never,\n\t\tadvanced: {\n\t\t\tcookies: {\n\t\t\t\tsessionToken: {\n\t\t\t\t\tattributes: {\n\t\t\t\t\t\tsameSite: (config.cookieSameSite ?? \"lax\") as\n\t\t\t\t\t\t\t| \"lax\"\n\t\t\t\t\t\t\t| \"strict\"\n\t\t\t\t\t\t\t| \"none\",\n\t\t\t\t\t\tsecure:\n\t\t\t\t\t\t\tconfig.cookieSecure ?? process.env[\"NODE_ENV\"] === \"production\",\n\t\t\t\t\t\t...(config.cookieDomain ? { domain: config.cookieDomain } : {}),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tcrossSubDomainCookies: config.crossSubDomainCookies?.enabled\n\t\t\t\t? {\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\tdomain: config.crossSubDomainCookies.domain,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t},\n\t\tplugins,\n\t} as never) as unknown as BetterAuthInstance;\n}\n\n/**\n * Type alias for the returned auth instance — convenient for DI token\n * typings.\n */\nexport type NexusAuth = ReturnType<typeof createAuth>;\n",
|
|
6
|
+
"/**\n * `AuthService` — DI-friendly wrapper around a better-auth instance.\n *\n * Why a service wrapper?\n * - Hides the raw better-auth object behind a stable NexusTS API.\n * - Exposes the high-level operations controllers need:\n * signUp, signIn, signOut, getSession, oauthUrl, jwt, passkey.\n * - Allows tests to swap the implementation via DI.\n *\n * Usage:\n * constructor(@Inject(AuthService.TOKEN) private auth: AuthService) {}\n *\n * await this.auth.signUp.email({ email, password, name });\n * const session = await this.auth.getSession({ headers: c.req.raw.headers });\n * return this.auth.redirect('/dashboard'); // 302\n */\n\nimport { Inject, Injectable } from \"@nexusts/core/decorators/index.js\";\nimport type {\n\tAuthUser,\n\tAuthSessionRecord,\n\tAuthSession,\n\tAuthConfig,\n} from \"./types.js\";\nimport { createAuth, type NexusAuth } from \"./auth.js\";\nimport type { SessionService } from \"@nexusts/session/index.js\";\n\n@Injectable()\nexport class AuthService {\n\t/** DI token — use with `@Inject(AuthService.TOKEN)`. */\n\tstatic readonly TOKEN = Symbol.for(\"nexus:AuthService\");\n\n\t/** The underlying better-auth instance. */\n\treadonly instance: NexusAuth;\n\n\t/**\n\t * Optional SessionService binding. When set, `getSession()` will\n\t * first check the SessionService's cookie before falling back to\n\t * better-auth. This enables shared session state between the two\n\t * modules (e.g. flash messages, guest cart).\n\t *\n\t * Set via `bindSession()` from a feature module's `onInit`, or via\n\t * DI when both modules are present.\n\t */\n\t#sessionService: SessionService | null = null;\n\n\tconstructor(\n\t\t@Inject(\"AUTH_CONFIG\") private readonly config: AuthConfig,\n\t) {\n\t\t// Lazy: defer construction to the first call so module-load\n\t\t// order doesn't matter.\n\t\tthis.instance = createAuth(this.config);\n\t}\n\n\t// ===========================================================================\n\t// Session integration\n\t// ===========================================================================\n\n\t/**\n\t * Bind a SessionService. When bound, `getSession()` consults the\n\t * SessionService first and falls back to better-auth. Returns `this`\n\t * for chaining.\n\t */\n\tbindSession(sessionService: SessionService): this {\n\t\tthis.#sessionService = sessionService;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns true when a SessionService has been bound.\n\t */\n\thasSessionBinding(): boolean {\n\t\treturn this.#sessionService !== null;\n\t}\n\n\t// ===========================================================================\n\t// Session\n\t// ===========================================================================\n\n\t/**\n\t * Get the current session from a request. Returns `null` if not\n\t * authenticated.\n\t *\n\t * When a SessionService is bound, we try it first (cookie-based,\n\t * stateless, edge-friendly); better-auth remains the source of\n\t * truth for `user` / `session` records. The cookie value carries\n\t * `userId` which lets you cross-reference both systems.\n\t */\n\tasync getSession(input: { headers: Headers }): Promise<AuthSession> {\n\t\t// 1) Try SessionService (cookie-based) first.\n\t\tif (this.#sessionService) {\n\t\t\tconst cookieName = this.#sessionService.cookieName;\n\t\t\tif (cookieName) {\n\t\t\t\tconst cookieHeader = input.headers.get(\"cookie\") ?? \"\";\n\t\t\t\tconst value = parseCookie(cookieHeader, cookieName);\n\t\t\t\tif (value) {\n\t\t\t\t\tconst decoded = this.#sessionService.decodeCookie(value);\n\t\t\t\t\tif (decoded?.userId) {\n\t\t\t\t\t\t// Hydrate the user from better-auth (so the returned\n\t\t\t\t\t\t// shape matches what controllers expect).\n\t\t\t\t\t\tconst fromBetterAuth = (await this.instance.api.getSession({\n\t\t\t\t\t\t\theaders: input.headers,\n\t\t\t\t\t\t})) as AuthSession | null;\n\t\t\t\t\t\tif (fromBetterAuth?.user) {\n\t\t\t\t\t\t\treturn fromBetterAuth;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// 2) Fallback to better-auth.\n\t\tconst result = await this.instance.api.getSession({\n\t\t\theaders: input.headers,\n\t\t});\n\t\treturn result as AuthSession;\n\t}\n\n\t/**\n\t * Read the raw SessionService record from a request (no better-auth\n\t * lookup). Returns null when no SessionService is bound or no\n\t * session is found.\n\t */\n\tasync getRawSession(input: { headers: Headers }) {\n\t\tif (!this.#sessionService) return null;\n\t\tconst cookieName = this.#sessionService.cookieName;\n\t\tif (!cookieName) return null;\n\t\tconst cookieHeader = input.headers.get(\"cookie\") ?? \"\";\n\t\tconst value = parseCookie(cookieHeader, cookieName);\n\t\tif (!value) return null;\n\t\treturn this.#sessionService.decodeCookie(value);\n\t}\n\n\t// ===========================================================================\n\t// Sign up / Sign in / Sign out\n\t// ===========================================================================\n\n\t/**\n\t * Email + password sign-up. Throws if email/password is disabled\n\t * in the auth config.\n\t */\n\tasync signUp(input: {\n\t\temail: string;\n\t\tpassword: string;\n\t\tname: string;\n\t\timage?: string;\n\t\tcallbackURL?: string;\n\t}) {\n\t\treturn this.instance.api.signUpEmail({\n\t\t\tbody: input as never,\n\t\t});\n\t}\n\n\t/** Email + password sign-in. */\n\tasync signIn(input: { email: string; password: string; callbackURL?: string }) {\n\t\treturn this.instance.api.signInEmail({\n\t\t\tbody: input as never,\n\t\t});\n\t}\n\n\t/** Sign out — invalidates the current session. */\n\tasync signOut(input: { headers: Headers }) {\n\t\treturn this.instance.api.signOut({\n\t\t\theaders: input.headers,\n\t\t});\n\t}\n\n\t// ===========================================================================\n\t// Social / OAuth\n\t// ===========================================================================\n\n\t/**\n\t * Get the URL the client should redirect to for a social sign-in.\n\t */\n\tasync getOAuthUrl(input: {\n\t\tprovider: string;\n\t\tcallbackURL?: string;\n\t}) {\n\t\treturn this.instance.api.signInSocial({\n\t\t\tbody: input as never,\n\t\t});\n\t}\n\n\t/**\n\t * Sign in / link a social account and return the user.\n\t */\n\tasync handleOAuthCallback(input: { headers: Headers; query: Record<string, string> }) {\n\t\treturn this.instance.api.signInSocial({\n\t\t\theaders: input.headers,\n\t\t\tquery: input.query,\n\t\t\tbody: {} as never,\n\t\t});\n\t}\n\n\t// ===========================================================================\n\t// JWT\n\t// ===========================================================================\n\n\t/**\n\t * Issue a JWT for the currently-authenticated user. Returns\n\t * `{ token, expiresAt }`. Requires the JWT plugin (`config.jwt.enabled`).\n\t */\n\tasync issueJwt(input: { userId: string }) {\n\t\tconst api = this.instance.api as unknown as {\n\t\t\tsignJWT?: (input: { body: { userId: string } }) => Promise<{\n\t\t\t\ttoken: string;\n\t\t\t\texpiresAt: Date;\n\t\t\t}>;\n\t\t};\n\t\tif (!api.signJWT) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[nexus/auth] JWT plugin not enabled. Set `auth.jwt.enabled: true` in nx.config.ts.\",\n\t\t\t);\n\t\t}\n\t\treturn api.signJWT({ body: { userId: input.userId } });\n\t}\n\n\t// ===========================================================================\n\t// Passkey\n\t// ===========================================================================\n\n\tasync registerPasskey(input: { headers: Headers }) {\n\t\tconst api = this.instance.api as unknown as {\n\t\t\tpasskey?: {\n\t\t\t\tregister: (input: { headers: Headers }) => Promise<unknown>;\n\t\t\t};\n\t\t};\n\t\tif (!api.passkey) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[nexus/auth] Passkey plugin not enabled. Set `auth.passkey.enabled: true` in nx.config.ts.\",\n\t\t\t);\n\t\t}\n\t\treturn api.passkey.register({ headers: input.headers });\n\t}\n\n\tasync authenticatePasskey(input: { headers: Headers; body: unknown }) {\n\t\tconst api = this.instance.api as unknown as {\n\t\t\tpasskey?: {\n\t\t\t\tauthenticate: (input: { headers: Headers; body: unknown }) => Promise<unknown>;\n\t\t\t};\n\t\t};\n\t\tif (!api.passkey) {\n\t\t\tthrow new Error(\"[nexus/auth] Passkey plugin not enabled.\");\n\t\t}\n\t\treturn api.passkey.authenticate({ headers: input.headers, body: input.body });\n\t}\n\n\t// ===========================================================================\n\t// Helpers\n\t// ===========================================================================\n\n\t/**\n\t * Build a redirect Response. Used by controllers that need to send\n\t * the user to a different page after sign-in / sign-up.\n\t */\n\tredirect(to: string, status: 302 | 303 | 307 | 308 = 302): Response {\n\t\treturn new Response(null, { status, headers: { Location: to } });\n\t}\n\n\t/**\n\t * Convert a session into the `AuthVariables` shape Hono expects.\n\t */\n\ttoContextVariables(session: AuthSession): {\n\t\tuser: AuthUser | null;\n\t\tsession: AuthSessionRecord | null;\n\t} {\n\t\tif (!session) return { user: null, session: null };\n\t\treturn { user: session.user, session: session.session };\n\t}\n}\n\n/**\n * Extract a single cookie value from a `Cookie` header string.\n * Tiny helper to avoid pulling in a cookie-parsing dependency.\n */\nfunction parseCookie(cookieHeader: string, name: string): string | null {\n\tif (!cookieHeader) return null;\n\tconst parts = cookieHeader.split(\";\");\n\tfor (const part of parts) {\n\t\tconst eq = part.indexOf(\"=\");\n\t\tif (eq < 0) continue;\n\t\tconst k = part.slice(0, eq).trim();\n\t\tif (k === name) {\n\t\t\treturn decodeURIComponent(part.slice(eq + 1).trim());\n\t\t}\n\t}\n\treturn null;\n}",
|
|
7
|
+
"/**\n * `AuthController` — built-in controller exposing common auth endpoints.\n *\n * Mount it in any `@Module` to get a working auth API:\n *\n * @Module({\n * controllers: [AuthController],\n * providers: [AuthService],\n * })\n * export class AuthModule {}\n *\n * Endpoints (all prefixed with `config.basePath`, default `/api/auth`):\n * - GET /session → current session\n * - POST /sign-up/email → email/password registration\n * - POST /sign-in/email → email/password login\n * - POST /sign-out → invalidate session\n * - GET /sign-in/:provider → start OAuth flow\n * - GET /callback/:provider → OAuth callback\n * - POST /jwt → issue JWT (JWT plugin only)\n * - POST /passkey/register → start passkey registration\n * - POST /passkey/authenticate → complete passkey auth\n *\n * Most of the actual logic is delegated to `auth.handler` from\n * better-auth. The controller exists to make the routes visible to\n * `nx route:list` and to add NexusTS-style DI.\n */\n\nimport {\n\tBody,\n\tController,\n\tGet,\n\tInject,\n\tPost,\n\tReq,\n\tRes,\n} from \"@nexusts/core/decorators/index.js\";\nimport type { Context } from \"hono\";\nimport { AuthService } from \"./auth.service.js\";\nimport type { AuthSession } from \"./types.js\";\n\n@Controller(\"/api/auth\")\nexport class AuthController {\n\tconstructor(@Inject(AuthService.TOKEN) private readonly auth: AuthService) {}\n\n\t/**\n\t * GET /api/auth/session\n\t * Returns the current session (or null if unauthenticated).\n\t */\n\t@Get(\"/session\")\n\tasync session(@Req() c: Context) {\n\t\tconst session: AuthSession = await this.auth.getSession({\n\t\t\theaders: c.req.raw.headers,\n\t\t});\n\t\treturn c.json(session ?? { user: null, session: null });\n\t}\n\n\t/**\n\t * POST /api/auth/sign-up/email\n\t * Body: { email, password, name, callbackURL? }\n\t */\n\t@Post(\"/sign-up/email\")\n\tasync signUpEmail(@Req() c: Context, @Body() body: any) {\n\t\tconst result = await this.auth.signUp(body);\n\t\treturn c.json(result, 201);\n\t}\n\n\t/**\n\t * POST /api/auth/sign-in/email\n\t * Body: { email, password, callbackURL? }\n\t */\n\t@Post(\"/sign-in/email\")\n\tasync signInEmail(@Req() c: Context, @Body() body: any) {\n\t\tconst result = await this.auth.signIn(body);\n\t\treturn c.json(result);\n\t}\n\n\t/**\n\t * POST /api/auth/sign-out\n\t */\n\t@Post(\"/sign-out\")\n\tasync signOut(@Req() c: Context, @Res() _res: Response) {\n\t\tawait this.auth.signOut({ headers: c.req.raw.headers });\n\t\treturn c.json({ ok: true });\n\t}\n\n\t/**\n\t * GET /api/auth/sign-in/:provider\n\t * Returns a redirect to the social provider's auth page.\n\t */\n\t@Get(\"/sign-in/:provider\")\n\tasync socialSignIn(\n\t\t@Req() c: Context,\n\t\t@Body() _body: never,\n\t) {\n\t\tconst provider = c.req.param(\"provider\") ?? \"\";\n\t\tconst callbackURL = c.req.query(\"callbackURL\") ?? \"/\";\n\t\tconst result = await this.auth.getOAuthUrl({ provider, callbackURL });\n\t\treturn c.json(result);\n\t}\n\n\t/**\n\t * GET /api/auth/callback/:provider\n\t * Social provider redirect target. The better-auth handler does the\n\t * real work; this is a passthrough for `route:list` visibility.\n\t */\n\t@Get(\"/callback/:provider\")\n\tasync oauthCallback(@Req() c: Context) {\n\t\tconst result = await this.auth.handleOAuthCallback({\n\t\t\theaders: c.req.raw.headers,\n\t\t\tquery: c.req.query() as Record<string, string>,\n\t\t});\n\t\treturn c.json(result);\n\t}\n\n\t/**\n\t * POST /api/auth/jwt\n\t * Issues a JWT for the current user. Requires the JWT plugin.\n\t */\n\t@Post(\"/jwt\")\n\tasync issueJwt(@Req() c: Context) {\n\t\tconst session = await this.auth.getSession({\n\t\t\theaders: c.req.raw.headers,\n\t\t});\n\t\tif (!session) return c.json({ error: \"Unauthorized\" }, 401);\n\t\tconst token = await this.auth.issueJwt({ userId: session.user.id });\n\t\treturn c.json(token);\n\t}\n\n\t/**\n\t * POST /api/auth/passkey/register\n\t * Start passkey registration. Requires the passkey plugin.\n\t */\n\t@Post(\"/passkey/register\")\n\tasync passkeyRegister(@Req() c: Context) {\n\t\tconst result = await this.auth.registerPasskey({\n\t\t\theaders: c.req.raw.headers,\n\t\t});\n\t\treturn c.json(result);\n\t}\n\n\t/**\n\t * POST /api/auth/passkey/authenticate\n\t * Body: passkey assertion\n\t */\n\t@Post(\"/passkey/authenticate\")\n\tasync passkeyAuthenticate(@Req() c: Context, @Body() body: any) {\n\t\tconst result = await this.auth.authenticatePasskey({\n\t\t\theaders: c.req.raw.headers,\n\t\t\tbody,\n\t\t});\n\t\treturn c.json(result);\n\t}\n}",
|
|
8
|
+
"/**\n * `AuthModule` — drop-in module for adding auth to any NexusTS app.\n *\n * Usage:\n * // src/app/app.module.ts\n * @Module({\n * imports: [AuthModule.forRoot({ ... })],\n * })\n * export class AppModule {}\n *\n * The `forRoot` static factory builds a one-off `AuthModule` subclass\n * pre-configured with the user's `auth` config. The provider token\n * `'AUTH_CONFIG'` carries the config to the `AuthService` constructor.\n *\n * AuthService is registered under **both** its class token and\n * `AuthService.TOKEN` (a Symbol). The class token is what the\n * container scans; the Symbol is what `@Inject(AuthService.TOKEN)`\n * looks up. Both resolve to the same instance via `useExisting`.\n */\n\nimport \"reflect-metadata\";\nimport { Module } from \"@nexusts/core/decorators/module.js\";\nimport { AuthController } from \"./auth.controller.js\";\nimport { AuthService } from \"./auth.service.js\";\nimport type { AuthConfig } from \"./types.js\";\n\n@Module({\n\tcontrollers: [AuthController],\n\tproviders: [\n\t\tAuthService,\n\t\t{ provide: AuthService.TOKEN, useExisting: AuthService },\n\t],\n\texports: [AuthService, AuthService.TOKEN],\n})\nexport class AuthModule {\n\t/**\n\t * Build a configured `AuthModule` class with the given config.\n\t *\n\t * The returned class can be `imports`-ed by any other module and\n\t * will provide the `AuthService` (and a `AUTH_CONFIG` value\n\t * provider) to its container.\n\t */\n\tstatic forRoot(config: AuthConfig) {\n\t\t@Module({\n\t\t\tcontrollers: [AuthController],\n\t\t\tproviders: [\n\t\t\t\tAuthService,\n\t\t\t\t{ provide: AuthService.TOKEN, useExisting: AuthService },\n\t\t\t\t{ provide: \"AUTH_CONFIG\", useValue: config },\n\t\t\t],\n\t\t\texports: [AuthService, AuthService.TOKEN],\n\t\t})\n\t\tclass ConfiguredAuthModule {}\n\n\t\t// Tag the dynamic class so the user can see where it came from.\n\t\tObject.defineProperty(ConfiguredAuthModule, \"name\", {\n\t\t\tvalue: \"ConfiguredAuthModule\",\n\t\t});\n\n\t\treturn ConfiguredAuthModule;\n\t}\n}\n",
|
|
9
|
+
"/**\n * `authMiddleware` — populate `c.var.user` and `c.var.session` on\n * every request, optionally enforcing a \"must be logged in\" policy.\n *\n * This is a Hono middleware that wraps better-auth's `getSession`.\n * It runs after the better-auth handler has set its own cookies, so\n * subsequent reads are cheap (a single DB lookup).\n *\n * Three modes:\n * - optional → always allow; populate user/session if present\n * - required → 401 if no user\n * - scoped → require user only for paths matching a regex\n *\n * Usage:\n * import { authMiddleware } from 'nexusjs/auth';\n * app.use('*', authMiddleware(auth, { mode: 'optional' }));\n * app.use('/api/*', authMiddleware(auth, { mode: 'required' }));\n */\n\nimport type { Context, MiddlewareHandler, Next } from \"hono\";\nimport type { Auth } from \"better-auth\";\nimport type { AuthVariables } from \"./types.js\";\n\nexport type AuthMiddlewareMode = \"optional\" | \"required\" | \"scoped\";\n\nexport interface AuthMiddlewareOptions {\n\t/** Auth mode. Default: `'optional'`. */\n\tmode?: AuthMiddlewareMode;\n\t/** Path matcher (only used in `'scoped'` mode). */\n\tscope?: RegExp;\n\t/** Path matcher for `'scoped'` mode's protected set. */\n\tprotectedPaths?: RegExp | RegExp[];\n\t/** Path matcher for paths that should be skipped entirely. */\n\tignoredPaths?: RegExp | RegExp[];\n\t/** Customize the 401 response. */\n\tonUnauthenticated?: (c: Context) => Response | Promise<Response>;\n\t/** Customize the 403 response when a scope check fails. */\n\tonForbidden?: (c: Context) => Response | Promise<Response>;\n}\n\nexport function authMiddleware(\n\tauth: Auth,\n\toptions: AuthMiddlewareOptions = {},\n): MiddlewareHandler<{ Variables: AuthVariables }> {\n\tconst {\n\t\tmode = \"optional\",\n\t\tscope,\n\t\tprotectedPaths,\n\t\tignoredPaths,\n\t\tonUnauthenticated = defaultUnauthenticated,\n\t\tonForbidden = defaultForbidden,\n\t} = options;\n\n\tconst ignored = toMatcher(ignoredPaths);\n\tconst protected_ =\n\t\tmode === \"scoped\"\n\t\t\t? toMatcher(scope ?? protectedPaths ?? /^\\/.+/) // everything\n\t\t\t: null;\n\n\treturn async (c, next) => {\n\t\tconst path = c.req.path;\n\n\t\t// Skip ignored paths entirely (e.g. health checks).\n\t\tif (ignored?.test(path)) {\n\t\t\treturn next();\n\t\t}\n\n\t\t// Populate the session.\n\t\tconst session = await auth.api.getSession({\n\t\t\theaders: c.req.raw.headers,\n\t\t});\n\n\t\tif (session) {\n\t\t\tc.set(\"user\", session.user as never);\n\t\t\tc.set(\"session\", session.session as never);\n\t\t} else {\n\t\t\tc.set(\"user\", null);\n\t\t\tc.set(\"session\", null);\n\t\t}\n\n\t\t// Apply mode.\n\t\tif (mode === \"required\" || (protected_?.test(path) && session === null)) {\n\t\t\tif (session === null) return onUnauthenticated(c);\n\t\t}\n\n\t\t// Scope-based forbidden check (e.g. \"user must have a specific role\").\n\t\t// Skipped here — the route handler can call `requireRole(...)` itself.\n\n\t\treturn next();\n\t};\n}\n\nfunction toMatcher(input?: RegExp | RegExp[]): RegExp | null {\n\tif (!input) return null;\n\tif (Array.isArray(input)) {\n\t\treturn new RegExp(input.map((r) => `(?:${r.source})`).join(\"|\"));\n\t}\n\treturn input;\n}\n\nfunction defaultUnauthenticated(c: Context): Response {\n\treturn c.json(\n\t\t{ error: \"Unauthorized\", message: \"Authentication required.\" },\n\t\t401,\n\t);\n}\n\nfunction defaultForbidden(c: Context): Response {\n\treturn c.json(\n\t\t{ error: \"Forbidden\", message: \"Insufficient permissions.\" },\n\t\t403,\n\t);\n}\n\n/**\n * `authHandler` — mount better-auth's catch-all handler at a path.\n *\n * Use this instead of writing the `app.on(['POST', 'GET'], path, ...)`\n * boilerplate yourself.\n *\n * app.use('/api/auth/*', cors({ ... }));\n * app.all('/api/auth/*', authHandler(auth));\n */\nexport function authHandler(auth: Auth): MiddlewareHandler {\n\treturn async (c) => auth.handler(c.req.raw);\n}\n",
|
|
10
|
+
"/**\n * `@CurrentUser()` — controller parameter decorator that injects the\n * authenticated user (and optionally the session) into a handler.\n *\n * Usage:\n * @Get('/me')\n * me(@CurrentUser() user: AuthUser) {\n * return user;\n * }\n *\n * @Get('/profile')\n * profile(@CurrentUser({ session: true }) ctx: { user: AuthUser; session: AuthSessionRecord }) {\n * return ctx;\n * }\n *\n * @Get('/dashboard')\n * dashboard(@CurrentUser({ required: true }) user: AuthUser) {\n * // 401 is thrown before the handler if no user is present.\n * return this.dashboardService.forUser(user.id);\n * }\n */\n\nimport \"reflect-metadata\";\nimport { createParamDecorator } from \"@nexusts/core/src/decorators/params.js\";\nimport { PARAM_TYPES } from \"@nexusts/core/src/constants.js\";\nimport type { AuthUser, AuthSessionRecord } from \"../types.js\";\n\nexport interface CurrentUserOptions {\n\t/**\n\t * Include the session in the injected value. Default: `false`.\n\t * When true, the value is `{ user, session }` instead of just the user.\n\t */\n\tsession?: boolean;\n\t/**\n\t * Throw 401 if no user is present. Default: `false`.\n\t * When true, the framework returns a 401 response without invoking\n\t * the handler.\n\t */\n\trequired?: boolean;\n\t/**\n\t * Throw 403 if the user does not satisfy the predicate.\n\t */\n\tassert?: (user: AuthUser) => boolean | Promise<boolean>;\n}\n\n/**\n * Inject the authenticated user (or `{ user, session }` if `session: true`).\n */\nexport function CurrentUser(\n\toptions: CurrentUserOptions = {},\n): ParameterDecorator {\n\treturn createParamDecorator(PARAM_TYPES.USER, options as never);\n}\n\n/**\n * Convenience: throw 401 with a JSON body when no user is present.\n * Exposed for users who want to enforce auth inside the handler.\n */\nexport class UnauthenticatedError extends Error {\n\treadonly status = 401;\n\tconstructor(message = \"Authentication required.\") {\n\t\tsuper(message);\n\t\tthis.name = \"UnauthenticatedError\";\n\t}\n}\n\nexport class ForbiddenError extends Error {\n\treadonly status = 403;\n\tconstructor(message = \"Insufficient permissions.\") {\n\t\tsuper(message);\n\t\tthis.name = \"ForbiddenError\";\n\t}\n}\n\n// Re-export session record type for convenience.\nexport type { AuthSessionRecord as AuthSession };\n"
|
|
11
|
+
],
|
|
12
|
+
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
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexusts/auth",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Authentication via better-auth integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "bun run ../../build.ts"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"nexusts",
|
|
24
|
+
"framework",
|
|
25
|
+
"bun"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"better-auth": "^1.6.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependenciesMeta": {
|
|
32
|
+
"better-auth": {
|
|
33
|
+
"optional": true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@nexusts/core": "^0.7.0"
|
|
38
|
+
}
|
|
39
|
+
}
|