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.
- package/README.md +221 -210
- package/dist/adapters/index.cjs +17 -0
- package/dist/adapters/index.cjs.map +7 -0
- package/{dist-lib/adapter.d.ts → dist/adapters/index.d.ts} +1 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +1 -0
- package/dist/adapters/index.js.map +7 -0
- package/dist/adapters/memory.cjs +55 -0
- package/dist/adapters/memory.cjs.map +7 -0
- package/{dist-lib/memoryAdapter.d.ts → dist/adapters/memory.d.ts} +2 -1
- package/dist/adapters/memory.d.ts.map +1 -0
- package/dist/adapters/memory.js +31 -0
- package/dist/adapters/memory.js.map +7 -0
- package/dist/adapters/mongoose.cjs +55 -0
- package/dist/adapters/mongoose.cjs.map +7 -0
- package/dist/adapters/mongoose.d.ts +9 -0
- package/dist/adapters/mongoose.d.ts.map +1 -0
- package/dist/adapters/mongoose.js +31 -0
- package/dist/adapters/mongoose.js.map +7 -0
- package/dist/core/index.cjs +113 -0
- package/dist/core/index.cjs.map +7 -0
- package/{dist-lib/core.d.ts → dist/core/index.d.ts} +5 -4
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +78 -0
- package/dist/core/index.js.map +7 -0
- package/dist/index.cjs +45 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +7 -0
- package/dist/providers/index.cjs +50 -0
- package/dist/providers/index.cjs.map +7 -0
- package/{dist-lib/providers.d.ts → dist/providers/index.d.ts} +1 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +25 -0
- package/dist/providers/index.js.map +7 -0
- package/dist/security/index.cjs +55 -0
- package/dist/security/index.cjs.map +7 -0
- package/{dist-lib/security.d.ts → dist/security/index.d.ts} +1 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +20 -0
- package/dist/security/index.js.map +7 -0
- package/package.json +82 -44
- package/dist-lib/adapter.js +0 -1
- package/dist-lib/core.js +0 -103
- package/dist-lib/index.d.ts +0 -7
- package/dist-lib/index.js +0 -4
- package/dist-lib/memoryAdapter.js +0 -34
- package/dist-lib/providers.js +0 -16
- 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
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
import {
|
|
53
|
-
import
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
}
|
|
@@ -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,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 "./
|
|
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
|
+
}
|