kroxt 1.1.3 → 1.1.5

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.
Files changed (51) hide show
  1. package/README.md +221 -210
  2. package/dist/adapters/index.cjs +17 -0
  3. package/dist/adapters/index.cjs.map +7 -0
  4. package/{dist-lib/adapter.d.ts → dist/adapters/index.d.ts} +1 -0
  5. package/dist/adapters/index.d.ts.map +1 -0
  6. package/dist/adapters/index.js +1 -0
  7. package/dist/adapters/index.js.map +7 -0
  8. package/dist/adapters/memory.cjs +55 -0
  9. package/dist/adapters/memory.cjs.map +7 -0
  10. package/{dist-lib/memoryAdapter.d.ts → dist/adapters/memory.d.ts} +2 -1
  11. package/dist/adapters/memory.d.ts.map +1 -0
  12. package/dist/adapters/memory.js +31 -0
  13. package/dist/adapters/memory.js.map +7 -0
  14. package/dist/adapters/mongoose.cjs +55 -0
  15. package/dist/adapters/mongoose.cjs.map +7 -0
  16. package/dist/adapters/mongoose.d.ts +9 -0
  17. package/dist/adapters/mongoose.d.ts.map +1 -0
  18. package/dist/adapters/mongoose.js +31 -0
  19. package/dist/adapters/mongoose.js.map +7 -0
  20. package/dist/core/index.cjs +113 -0
  21. package/dist/core/index.cjs.map +7 -0
  22. package/{dist-lib/core.d.ts → dist/core/index.d.ts} +5 -4
  23. package/dist/core/index.d.ts.map +1 -0
  24. package/dist/core/index.js +78 -0
  25. package/dist/core/index.js.map +7 -0
  26. package/dist/index.cjs +45 -0
  27. package/dist/index.cjs.map +7 -0
  28. package/dist/index.d.ts +9 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +14 -0
  31. package/dist/index.js.map +7 -0
  32. package/dist/providers/index.cjs +50 -0
  33. package/dist/providers/index.cjs.map +7 -0
  34. package/{dist-lib/providers.d.ts → dist/providers/index.d.ts} +1 -0
  35. package/dist/providers/index.d.ts.map +1 -0
  36. package/dist/providers/index.js +25 -0
  37. package/dist/providers/index.js.map +7 -0
  38. package/dist/security/index.cjs +55 -0
  39. package/dist/security/index.cjs.map +7 -0
  40. package/{dist-lib/security.d.ts → dist/security/index.d.ts} +1 -0
  41. package/dist/security/index.d.ts.map +1 -0
  42. package/dist/security/index.js +20 -0
  43. package/dist/security/index.js.map +7 -0
  44. package/package.json +82 -44
  45. package/dist-lib/adapter.js +0 -1
  46. package/dist-lib/core.js +0 -103
  47. package/dist-lib/index.d.ts +0 -7
  48. package/dist-lib/index.js +0 -4
  49. package/dist-lib/memoryAdapter.js +0 -34
  50. package/dist-lib/providers.js +0 -16
  51. package/dist-lib/security.js +0 -29
package/README.md CHANGED
@@ -1,210 +1,221 @@
1
- # kroxt
2
-
3
- A framework-agnostic, modular authentication engine for modern TypeScript applications. Built for security, extensibility, and ease of use.
4
-
5
- ## Features
6
-
7
- - 🔐 **Secure Hashing**: Powered by `argon2` for industry-standard password security.
8
- - 🎟️ **Dual-Token Sessions**: Native support for Access and Refresh tokens via `jose`.
9
- - 🧩 **JWT Customization**: Fully extensible payload with support for custom user fields and `sub` override.
10
- - 🌍 **OAuth Ready**: Built-in support for GitHub and Google OAuth via `arctic`.
11
- - 🧩 **Database Agnostic**: Use Mongoose, Prisma, Drizzle, or any store via the `AuthAdapter` pattern.
12
- - 🌶️ **Password Peppering**: Server-side pepper support for enhanced hash protection.
13
- - 🛡️ **Timing Attack Protection**: Built-in safeguards against side-channel analysis during login.
14
- - **Zod Schema Support**: Perfectly preserves and types your user metadata.
15
- - 🚀 **ESM First**: Native support for NodeNext module resolution.
16
-
17
- ## Installation
18
-
19
- ```bash
20
- npm install kroxt
21
- ```
22
-
23
- ---
24
-
25
- ## Guide: Full Authentication Flow
26
-
27
- This guide walks you through setting up Kroxt from scratch in your application.
28
-
29
- ### Step 1: Define your User
30
-
31
- First, define what a User looks like in your system. Kroxt allows any additional fields (like `role`, `schoolId`, etc.) which you can later sign into your JWTs.
32
-
33
- ```typescript
34
- export interface MyUser {
35
- id: string;
36
- email: string;
37
- passwordHash: string;
38
- role: 'admin' | 'user';
39
- schoolId: string; // Custom field for enterprise/multi-tenant apps
40
- oauthProvider?: string; // Support for OAuth (e.g., 'github')
41
- oauthId?: string; // Unique ID from the provider
42
- name: string;
43
- }
44
- ```
45
-
46
- ### Step 2: The Adapter Pattern
47
-
48
- Kroxt doesn't care which database you use. You just need to implement the `AuthAdapter` interface using your model. Here is a complete example using Mongoose:
49
-
50
- ```typescript
51
- import type { AuthAdapter } from "kroxt/adapter";
52
- import { User } from "./models/user.model.js"; // Your Mongoose model
53
- import type { MyUser } from "./types.js";
54
-
55
- export const myAdapter: AuthAdapter<MyUser> = {
56
- createUser: async (data) => {
57
- const user = await User.create(data);
58
- const obj = user.toObject();
59
- return { ...obj, id: obj._id.toString() };
60
- },
61
- findUserByEmail: async (email) => {
62
- const user = await User.findOne({ email });
63
- if (!user) return null;
64
- const obj = user.toObject();
65
- return { ...obj, id: obj._id.toString() };
66
- },
67
- findUserById: async (id) => {
68
- const user = await User.findById(id);
69
- if (!user) return null;
70
- const obj = user.toObject();
71
- return { ...obj, id: obj._id.toString() };
72
- },
73
- linkOAuthAccount: async (userId, provider, providerId) => {
74
- await User.findByIdAndUpdate(userId, {
75
- oauthProvider: provider,
76
- oauthId: providerId
77
- });
78
- }
79
- };
80
- ```
81
-
82
- ### Step 3: Initialize the Auth Engine
83
-
84
- Configure Kroxt with your adapter and security settings.
85
-
86
- ```typescript
87
- import { createAuth } from "kroxt";
88
- import { myAdapter } from "./myAdapter.js";
89
-
90
- export const auth = createAuth({
91
- adapter: myAdapter,
92
- secret: process.env.AUTH_SECRET, // High-entropy secret for JWT signing
93
- pepper: process.env.AUTH_PEPPER, // Optional: Server-side pepper for password hashing
94
- session: {
95
- expires: "15m", // Access token duration
96
- refreshExpires: "7d" // Refresh token duration
97
- },
98
- jwt: {
99
- /**
100
- * Optional: Fully customize the JWT payload or add extra fields.
101
- */
102
- payload: (user, type) => {
103
- // Only add extra details to 'access' tokens to keep 'refresh' tokens light.
104
- if (type === "access") {
105
- return {
106
- schoolId: user.schoolId, // Add custom user detail
107
- role: user.role, // Explicitly include role
108
- };
109
- }
110
- return {}; // Refresh tokens stay minimal
111
- }
112
- }
113
- });
114
- ```
115
-
116
- ### Step 4: Implement Controllers & Routes
117
-
118
- Use the engine in your application logic. Examples below use an Express-like structure.
119
-
120
- #### Registration
121
- ```typescript
122
- app.post("/register", async (req, res) => {
123
- const { name, email, password, ...extraFields } = req.body;
124
-
125
- // Kroxt handles argon2 hashing (with pepper) and token generation
126
- const { user, accessToken, refreshToken } = await auth.signup({
127
- name,
128
- email,
129
- ...extraFields
130
- }, password);
131
-
132
- res.json({ user, accessToken, refreshToken });
133
- });
134
- ```
135
-
136
- #### Login
137
- ```typescript
138
- app.post("/login", async (req, res) => {
139
- const { email, password } = req.body;
140
-
141
- // Kroxt verifies password (timing-attack safe) and returns tokens
142
- const { user, accessToken, refreshToken } = await auth.loginWithPassword(email, password);
143
-
144
- res.json({ user, accessToken, refreshToken });
145
- });
146
- ```
147
-
148
- #### Token Refresh
149
- Keep users logged in by rotating access tokens using a valid refresh token.
150
- ```typescript
151
- app.post("/refresh", async (req, res) => {
152
- const { refreshToken } = req.body;
153
-
154
- // Returns a fresh access token
155
- const { accessToken } = await auth.refresh(refreshToken);
156
-
157
- res.json({ accessToken });
158
- });
159
- ```
160
-
161
- #### Protecting Routes (Middleware)
162
- ```typescript
163
- app.get("/me", async (req, res) => {
164
- const token = req.headers.authorization?.split(" ")[1];
165
-
166
- // Verify the JWT and get the payload { sub: string, role: string, ... }
167
- const payload = await auth.verifyToken(token, "access");
168
-
169
- if (!payload) return res.status(401).send("Unauthorized");
170
-
171
- const user = await myAdapter.findUserById(payload.sub);
172
- res.json(user);
173
- });
174
- ```
175
-
176
- ---
177
-
178
- ## Security Best Practices
179
-
180
- ### 1. Password Peppering
181
- Always use a `pepper` in production. It's a server-side secret added to passwords before hashing. If your database is leaked, the hashes cannot be cracked without this pepper.
182
-
183
- ### 2. CSRF Protection
184
- Kroxt provides helpers for the double-submit cookie pattern. Use these if you are storing tokens in cookies.
185
-
186
- ```typescript
187
- import { generateCsrfToken, verifyCsrf } from "kroxt/security";
188
-
189
- const token = generateCsrfToken();
190
- const isValid = verifyCsrf(tokenInRequest, tokenInCookie);
191
- ```
192
-
193
- ### 3. Secure Cookies
194
- If using cookies, always set these flags:
195
- - `httpOnly: true` (Prevents XSS)
196
- - `secure: true` (Requires HTTPS)
197
- - `sameSite: 'strict'` (Prevents CSRF)
198
-
199
- ### 4. Rate Limiting
200
- Implement rate limiting (e.g., `express-rate-limit`) on `/login` and `/register` to block brute-force attempts.
201
-
202
- ---
203
-
204
- ## Reference Project
205
-
206
- Check out the `kroxt-example` folder or the [GitHub repository](https://github.com/adepoju-oluwatobi/kroxt-example) for a complete **Express + MongoDB** implementation using this library.
207
-
208
- ## License
209
-
210
- MIT
1
+ # kroxt
2
+
3
+ A framework-agnostic, modular authentication engine for modern TypeScript applications. Built for security, extensibility, and ease of use.
4
+
5
+ ## Features
6
+
7
+ - 🔐 **Secure Hashing**: Powered by `argon2` for industry-standard password security.
8
+ - 🎟️ **Dual-Token Sessions**: Native support for Access and Refresh tokens via `jose`.
9
+ - 🧩 **JWT Customization**: Fully extensible payload with support for custom user fields and `sub` override.
10
+ - 🌍 **OAuth Ready**: Built-in support for GitHub and Google OAuth via `arctic`.
11
+ - 🔌 **Built-in Adapters**: Native, one-line support for **MongoDB (Mongoose)** and **In-Memory** stores.
12
+ - 🧩 **Database Agnostic**: Use Prisma, Drizzle, or any store via the generic `AuthAdapter` pattern.
13
+ - 🌶️ **Password Peppering**: Server-side pepper support for enhanced hash protection.
14
+ - 🛡️ **Timing Attack Protection**: Built-in safeguards against side-channel analysis during login.
15
+ - **Zod Schema Support**: Perfectly preserves and types your user metadata.
16
+ - 🌍 **Dual ESM/CJS Support**: Native support for both modern ESM (`import`) and CommonJS (`require`).
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install kroxt
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Guide: Full Authentication Flow
27
+
28
+ This guide walks you through setting up Kroxt from scratch in your application.
29
+
30
+ ### Step 1: Define your User
31
+
32
+ First, define what a User looks like in your system. Kroxt allows any additional fields (like `role`, `schoolId`, etc.) which you can later sign into your JWTs.
33
+
34
+ ```typescript
35
+ export interface MyUser {
36
+ id: string;
37
+ email: string;
38
+ passwordHash: string;
39
+ role: 'admin' | 'user';
40
+ schoolId: string; // Custom field for enterprise/multi-tenant apps
41
+ oauthProvider?: string; // Support for OAuth (e.g., 'github')
42
+ oauthId?: string; // Unique ID from the provider
43
+ name: string;
44
+ }
45
+ ```
46
+
47
+ ### Step 2: Choose an Adapter
48
+
49
+ Kroxt provides built-in adapters for popular databases. For MongoDB, simply pass your Mongoose model to `createMongoAdapter`.
50
+
51
+ ```typescript
52
+ import { createMongoAdapter } from "kroxt/adapters/mongoose";
53
+ import { User } from "./models/user.model.js"; // Your Mongoose model
54
+
55
+ // One line to connect your DB
56
+ export const authAdapter = createMongoAdapter(User);
57
+ ```
58
+
59
+ > [!TIP]
60
+ > Need to use Prisma, Drizzle, or a custom API? You can still build a [Custom Adapter](#custom-adapters).
61
+
62
+ ### Step 3: Initialize the Auth Engine
63
+
64
+ Configure Kroxt with your adapter and security settings.
65
+
66
+ ```typescript
67
+ import { createAuth } from "kroxt/core";
68
+ import { authAdapter } from "./auth.js";
69
+
70
+ export const auth = createAuth({
71
+ adapter: authAdapter,
72
+ secret: process.env.AUTH_SECRET, // High-entropy secret for JWT signing
73
+ pepper: process.env.AUTH_PEPPER, // Optional: Server-side pepper for password hashing
74
+ session: {
75
+ expires: "15m", // Access token duration
76
+ refreshExpires: "7d" // Refresh token duration
77
+ },
78
+ jwt: {
79
+ /**
80
+ * Optional: Fully customize the JWT payload or add extra fields.
81
+ */
82
+ payload: (user, type) => {
83
+ // Only add extra details to 'access' tokens to keep 'refresh' tokens light.
84
+ if (type === "access") {
85
+ return {
86
+ schoolId: user.schoolId, // Add custom user detail
87
+ role: user.role, // Explicitly include role
88
+ };
89
+ }
90
+ return {}; // Refresh tokens stay minimal
91
+ }
92
+ }
93
+ });
94
+ ```
95
+
96
+ ### Step 4: Implement Controllers & Routes
97
+
98
+ Use the engine in your application logic. Examples below use an Express-like structure.
99
+
100
+ #### Registration
101
+ ```typescript
102
+ app.post("/register", async (req, res) => {
103
+ const { name, email, password, ...extraFields } = req.body;
104
+
105
+ // Kroxt handles argon2 hashing (with pepper) and token generation
106
+ const { user, accessToken, refreshToken } = await auth.signup({
107
+ name,
108
+ email,
109
+ ...extraFields
110
+ }, password);
111
+
112
+ res.json({ user, accessToken, refreshToken });
113
+ });
114
+ ```
115
+
116
+ #### Login
117
+ ```typescript
118
+ app.post("/login", async (req, res) => {
119
+ const { email, password } = req.body;
120
+
121
+ // Kroxt verifies password (timing-attack safe) and returns tokens
122
+ const { user, accessToken, refreshToken } = await auth.loginWithPassword(email, password);
123
+
124
+ res.json({ user, accessToken, refreshToken });
125
+ });
126
+ ```
127
+
128
+ #### Token Refresh
129
+ Keep users logged in by rotating access tokens using a valid refresh token.
130
+ ```typescript
131
+ app.post("/refresh", async (req, res) => {
132
+ const { refreshToken } = req.body;
133
+
134
+ // Returns a fresh access token
135
+ const { accessToken } = await auth.refresh(refreshToken);
136
+
137
+ res.json({ accessToken });
138
+ });
139
+ ```
140
+
141
+ #### Protecting Routes (Middleware)
142
+ ```typescript
143
+ app.get("/me", async (req, res) => {
144
+ const token = req.headers.authorization?.split(" ")[1];
145
+
146
+ // Verify the JWT and get the payload { sub: string, role: string, ... }
147
+ const payload = await auth.verifyToken(token, "access");
148
+
149
+ if (!payload) return res.status(401).send("Unauthorized");
150
+
151
+ const user = await myAdapter.findUserById(payload.sub);
152
+ res.json(user);
153
+ });
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Custom Adapters
159
+
160
+ Kroxt's true power lies in its database-agnostic design. If you aren't using a built-in adapter, simply implement the `AuthAdapter` interface.
161
+
162
+ ```typescript
163
+ import type { AuthAdapter, User } from "kroxt/adapters";
164
+ import { db } from "./db.js";
165
+
166
+ // Example using a generic DB client
167
+ export const myCustomAdapter: AuthAdapter<MyUser> = {
168
+ createUser: async (data) => {
169
+ const user = await db.users.insert(data);
170
+ return { ...user, id: user.id.toString() };
171
+ },
172
+ findUserByEmail: async (email) => {
173
+ return await db.users.findFirst({ where: { email } });
174
+ },
175
+ findUserById: async (id) => {
176
+ return await db.users.findUnique({ where: { id } });
177
+ },
178
+ linkOAuthAccount: async (id, provider, providerId) => {
179
+ await db.users.update({
180
+ where: { id },
181
+ data: { oauthProvider: provider, oauthId: providerId }
182
+ });
183
+ }
184
+ };
185
+ ```
186
+
187
+ Using this pattern, you can connect Kroxt to **Supabase**, **Firestore**, **PostgreSQL**, or even a 3rd-party API.
188
+
189
+ ## Security Best Practices
190
+
191
+ ### 1. Password Peppering
192
+ Always use a `pepper` in production. It's a server-side secret added to passwords before hashing. If your database is leaked, the hashes cannot be cracked without this pepper.
193
+
194
+ ### 2. CSRF Protection
195
+ Kroxt provides helpers for the double-submit cookie pattern. Use these if you are storing tokens in cookies.
196
+
197
+ ```typescript
198
+ import { generateCsrfToken, verifyCsrf } from "kroxt/security";
199
+
200
+ const token = generateCsrfToken();
201
+ const isValid = verifyCsrf(tokenInRequest, tokenInCookie);
202
+ ```
203
+
204
+ ### 3. Secure Cookies
205
+ If using cookies, always set these flags:
206
+ - `httpOnly: true` (Prevents XSS)
207
+ - `secure: true` (Requires HTTPS)
208
+ - `sameSite: 'strict'` (Prevents CSRF)
209
+
210
+ ### 4. Rate Limiting
211
+ Implement rate limiting (e.g., `express-rate-limit`) on `/login` and `/register` to block brute-force attempts.
212
+
213
+ ---
214
+
215
+ ## Reference Project
216
+
217
+ Check out the `kroxt-example` folder or the [GitHub repository](https://github.com/adepoju-oluwatobi/kroxt-example) for a complete **Express + MongoDB** implementation using this library.
218
+
219
+ ## License
220
+
221
+ MIT
@@ -0,0 +1,17 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var adapters_exports = {};
16
+ module.exports = __toCommonJS(adapters_exports);
17
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/auth/adapters/index.ts"],
4
+ "sourcesContent": ["export interface BaseUser {\n id: string;\n email: string;\n passwordHash?: string;\n role?: string;\n}\n\n// Allows any extended fields natively (like nin, bvn, maritalStatus, etc.)\nexport type User<TExtended = Record<string, any>> = BaseUser & TExtended;\n\nexport interface AuthAdapter<TUser = User> {\n createUser: (data: any) => Promise<TUser>;\n findUserByEmail: (email: string) => Promise<TUser | null>;\n findUserById: (id: string) => Promise<TUser | null>;\n linkOAuthAccount: (userId: string, provider: string, providerId: string) => Promise<void>;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -11,3 +11,4 @@ export interface AuthAdapter<TUser = User> {
11
11
  findUserById: (id: string) => Promise<TUser | null>;
12
12
  linkOAuthAccount: (userId: string, provider: string, providerId: string) => Promise<void>;
13
13
  }
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/adapters/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,WAAW,WAAW,CAAC,KAAK,GAAG,IAAI;IACvC,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;IAC1C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC1D,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACpD,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3F"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,55 @@
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
+ var memory_exports = {};
20
+ __export(memory_exports, {
21
+ createMemoryAdapter: () => createMemoryAdapter
22
+ });
23
+ module.exports = __toCommonJS(memory_exports);
24
+ function createMemoryAdapter() {
25
+ const users = /* @__PURE__ */ new Map();
26
+ const accounts = /* @__PURE__ */ new Map();
27
+ return {
28
+ createUser: async (data) => {
29
+ const id = data.id || Date.now().toString();
30
+ const newUser = { ...data, id };
31
+ users.set(newUser.email, newUser);
32
+ return newUser;
33
+ },
34
+ findUserByEmail: async (email) => {
35
+ return users.get(email) || null;
36
+ },
37
+ findUserById: async (id) => {
38
+ for (const user of users.values()) {
39
+ if (user.id === id) {
40
+ return user;
41
+ }
42
+ }
43
+ return null;
44
+ },
45
+ linkOAuthAccount: async (userId, provider, providerId) => {
46
+ const accountId = `${provider}_${providerId}`;
47
+ accounts.set(accountId, { userId, provider, providerId });
48
+ }
49
+ };
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ createMemoryAdapter
54
+ });
55
+ //# sourceMappingURL=memory.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/auth/adapters/memory.ts"],
4
+ "sourcesContent": ["import type { AuthAdapter, User } from \"./index.js\";\n\n/**\n * Creates an in-memory database adapter for the auth engine.\n * This is useful for testing, prototyping, or when you don't need persistent storage.\n * All data is kept in memory and is lost when the server restarts.\n */\nexport function createMemoryAdapter<TUser extends User = User>(): AuthAdapter<TUser> {\n const users = new Map<string, TUser>();\n const accounts = new Map<string, { userId: string; provider: string; providerId: string }>();\n\n return {\n createUser: async (data: any) => {\n // Auto-generate ID if not provided\n const id = data.id || Date.now().toString();\n const newUser = { ...data, id } as TUser;\n\n // Store using email as the primary lookup key\n users.set(newUser.email, newUser);\n return newUser;\n },\n\n findUserByEmail: async (email: string) => {\n return users.get(email) || null;\n },\n\n findUserById: async (id: string) => {\n for (const user of users.values()) {\n if (user.id === id) {\n return user;\n }\n }\n return null;\n },\n\n linkOAuthAccount: async (userId: string, provider: string, providerId: string) => {\n const accountId = `${provider}_${providerId}`;\n accounts.set(accountId, { userId, provider, providerId });\n }\n };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,sBAAqE;AACjF,QAAM,QAAQ,oBAAI,IAAmB;AACrC,QAAM,WAAW,oBAAI,IAAsE;AAE3F,SAAO;AAAA,IACH,YAAY,OAAO,SAAc;AAE7B,YAAM,KAAK,KAAK,MAAM,KAAK,IAAI,EAAE,SAAS;AAC1C,YAAM,UAAU,EAAE,GAAG,MAAM,GAAG;AAG9B,YAAM,IAAI,QAAQ,OAAO,OAAO;AAChC,aAAO;AAAA,IACX;AAAA,IAEA,iBAAiB,OAAO,UAAkB;AACtC,aAAO,MAAM,IAAI,KAAK,KAAK;AAAA,IAC/B;AAAA,IAEA,cAAc,OAAO,OAAe;AAChC,iBAAW,QAAQ,MAAM,OAAO,GAAG;AAC/B,YAAI,KAAK,OAAO,IAAI;AAChB,iBAAO;AAAA,QACX;AAAA,MACJ;AACA,aAAO;AAAA,IACX;AAAA,IAEA,kBAAkB,OAAO,QAAgB,UAAkB,eAAuB;AAC9E,YAAM,YAAY,GAAG,QAAQ,IAAI,UAAU;AAC3C,eAAS,IAAI,WAAW,EAAE,QAAQ,UAAU,WAAW,CAAC;AAAA,IAC5D;AAAA,EACJ;AACJ;",
6
+ "names": []
7
+ }
@@ -1,7 +1,8 @@
1
- import type { AuthAdapter, User } from "./adapter.js";
1
+ import type { AuthAdapter, User } from "./index.js";
2
2
  /**
3
3
  * Creates an in-memory database adapter for the auth engine.
4
4
  * This is useful for testing, prototyping, or when you don't need persistent storage.
5
5
  * All data is kept in memory and is lost when the server restarts.
6
6
  */
7
7
  export declare function createMemoryAdapter<TUser extends User = User>(): AuthAdapter<TUser>;
8
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/auth/adapters/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,SAAS,IAAI,GAAG,IAAI,KAAK,WAAW,CAAC,KAAK,CAAC,CAiCnF"}
@@ -0,0 +1,31 @@
1
+ function createMemoryAdapter() {
2
+ const users = /* @__PURE__ */ new Map();
3
+ const accounts = /* @__PURE__ */ new Map();
4
+ return {
5
+ createUser: async (data) => {
6
+ const id = data.id || Date.now().toString();
7
+ const newUser = { ...data, id };
8
+ users.set(newUser.email, newUser);
9
+ return newUser;
10
+ },
11
+ findUserByEmail: async (email) => {
12
+ return users.get(email) || null;
13
+ },
14
+ findUserById: async (id) => {
15
+ for (const user of users.values()) {
16
+ if (user.id === id) {
17
+ return user;
18
+ }
19
+ }
20
+ return null;
21
+ },
22
+ linkOAuthAccount: async (userId, provider, providerId) => {
23
+ const accountId = `${provider}_${providerId}`;
24
+ accounts.set(accountId, { userId, provider, providerId });
25
+ }
26
+ };
27
+ }
28
+ export {
29
+ createMemoryAdapter
30
+ };
31
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/auth/adapters/memory.ts"],
4
+ "sourcesContent": ["import type { AuthAdapter, User } from \"./index.js\";\n\n/**\n * Creates an in-memory database adapter for the auth engine.\n * This is useful for testing, prototyping, or when you don't need persistent storage.\n * All data is kept in memory and is lost when the server restarts.\n */\nexport function createMemoryAdapter<TUser extends User = User>(): AuthAdapter<TUser> {\n const users = new Map<string, TUser>();\n const accounts = new Map<string, { userId: string; provider: string; providerId: string }>();\n\n return {\n createUser: async (data: any) => {\n // Auto-generate ID if not provided\n const id = data.id || Date.now().toString();\n const newUser = { ...data, id } as TUser;\n\n // Store using email as the primary lookup key\n users.set(newUser.email, newUser);\n return newUser;\n },\n\n findUserByEmail: async (email: string) => {\n return users.get(email) || null;\n },\n\n findUserById: async (id: string) => {\n for (const user of users.values()) {\n if (user.id === id) {\n return user;\n }\n }\n return null;\n },\n\n linkOAuthAccount: async (userId: string, provider: string, providerId: string) => {\n const accountId = `${provider}_${providerId}`;\n accounts.set(accountId, { userId, provider, providerId });\n }\n };\n}\n"],
5
+ "mappings": "AAOO,SAAS,sBAAqE;AACjF,QAAM,QAAQ,oBAAI,IAAmB;AACrC,QAAM,WAAW,oBAAI,IAAsE;AAE3F,SAAO;AAAA,IACH,YAAY,OAAO,SAAc;AAE7B,YAAM,KAAK,KAAK,MAAM,KAAK,IAAI,EAAE,SAAS;AAC1C,YAAM,UAAU,EAAE,GAAG,MAAM,GAAG;AAG9B,YAAM,IAAI,QAAQ,OAAO,OAAO;AAChC,aAAO;AAAA,IACX;AAAA,IAEA,iBAAiB,OAAO,UAAkB;AACtC,aAAO,MAAM,IAAI,KAAK,KAAK;AAAA,IAC/B;AAAA,IAEA,cAAc,OAAO,OAAe;AAChC,iBAAW,QAAQ,MAAM,OAAO,GAAG;AAC/B,YAAI,KAAK,OAAO,IAAI;AAChB,iBAAO;AAAA,QACX;AAAA,MACJ;AACA,aAAO;AAAA,IACX;AAAA,IAEA,kBAAkB,OAAO,QAAgB,UAAkB,eAAuB;AAC9E,YAAM,YAAY,GAAG,QAAQ,IAAI,UAAU;AAC3C,eAAS,IAAI,WAAW,EAAE,QAAQ,UAAU,WAAW,CAAC;AAAA,IAC5D;AAAA,EACJ;AACJ;",
6
+ "names": []
7
+ }