@terreno/api 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +7 -1
- package/dist/betterAuthSetup.js +14 -8
- package/dist/expressServer.js +1 -1
- package/dist/terrenoApp.js +1 -1
- package/package.json +1 -1
- package/src/auth.ts +7 -1
- package/src/betterAuthSetup.ts +3 -1
- package/src/expressServer.ts +1 -1
- package/src/terrenoApp.ts +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface UserModel extends Model<User> {
|
|
|
19
19
|
deserializeUser(): any;
|
|
20
20
|
findByUsername(username: string, findOpts: any): any;
|
|
21
21
|
}
|
|
22
|
-
export declare function authenticateMiddleware(anonymous?: boolean): any;
|
|
22
|
+
export declare function authenticateMiddleware(anonymous?: boolean): (req: any, res: any, next: any) => any;
|
|
23
23
|
export declare function signupUser(userModel: UserModel, email: string, password: string, body?: any): Promise<any>;
|
|
24
24
|
/**
|
|
25
25
|
* Generates both an access token (JWT) and a refresh token for a given user.
|
package/dist/auth.js
CHANGED
|
@@ -82,11 +82,17 @@ function authenticateMiddleware(anonymous) {
|
|
|
82
82
|
if (anonymous) {
|
|
83
83
|
strategies.push("anonymous");
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
var passportAuth = passport_1.default.authenticate(strategies, {
|
|
86
86
|
failureMessage: false, // this is just avoiding storing the message in the session
|
|
87
87
|
failWithError: true,
|
|
88
88
|
session: false,
|
|
89
89
|
});
|
|
90
|
+
return function (req, res, next) {
|
|
91
|
+
if (req.user) {
|
|
92
|
+
return next();
|
|
93
|
+
}
|
|
94
|
+
return passportAuth(req, res, next);
|
|
95
|
+
};
|
|
90
96
|
}
|
|
91
97
|
function signupUser(userModel, email, password, body) {
|
|
92
98
|
return __awaiter(this, void 0, void 0, function () {
|
package/dist/betterAuthSetup.js
CHANGED
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* This module provides functions to initialize Better Auth with MongoDB,
|
|
6
6
|
* create session middleware, and sync users with the application User model.
|
|
7
7
|
*/
|
|
8
|
+
var __assign = (this && this.__assign) || function () {
|
|
9
|
+
__assign = Object.assign || function(t) {
|
|
10
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
+
s = arguments[i];
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
return __assign.apply(this, arguments);
|
|
18
|
+
};
|
|
8
19
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
20
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
21
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -169,7 +180,7 @@ exports.createBetterAuthSessionMiddleware = createBetterAuthSessionMiddleware;
|
|
|
169
180
|
* Creates or updates the user as needed.
|
|
170
181
|
*/
|
|
171
182
|
var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider) { return __awaiter(void 0, void 0, void 0, function () {
|
|
172
|
-
var existingUser, userByEmail, newUser, error_2;
|
|
183
|
+
var existingUser, userByEmail, useAsId, newUser, error_2;
|
|
173
184
|
return __generator(this, function (_a) {
|
|
174
185
|
switch (_a.label) {
|
|
175
186
|
case 0:
|
|
@@ -201,13 +212,8 @@ var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider) { r
|
|
|
201
212
|
_a.sent();
|
|
202
213
|
return [2 /*return*/, userByEmail];
|
|
203
214
|
case 6:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
betterAuthId: betterAuthUser.id,
|
|
207
|
-
email: betterAuthUser.email,
|
|
208
|
-
name: betterAuthUser.name || betterAuthUser.email.split("@")[0],
|
|
209
|
-
oauthProvider: oauthProvider || null,
|
|
210
|
-
});
|
|
215
|
+
useAsId = mongoose_1.default.isValidObjectId(betterAuthUser.id) ? { _id: betterAuthUser.id } : {};
|
|
216
|
+
newUser = new userModel(__assign(__assign({}, useAsId), { admin: false, betterAuthId: betterAuthUser.id, email: betterAuthUser.email, name: betterAuthUser.name || betterAuthUser.email.split("@")[0], oauthProvider: oauthProvider || null }));
|
|
211
217
|
return [4 /*yield*/, newUser.save()];
|
|
212
218
|
case 7:
|
|
213
219
|
_a.sent();
|
package/dist/expressServer.js
CHANGED
|
@@ -242,7 +242,7 @@ function initializeRoutes(UserModel, addRoutes, options) {
|
|
|
242
242
|
if (options.addMiddleware) {
|
|
243
243
|
options.addMiddleware(app);
|
|
244
244
|
}
|
|
245
|
-
app.use(express_1.default.json());
|
|
245
|
+
app.use(express_1.default.json({ limit: "50mb" }));
|
|
246
246
|
// Add login/signup/refresh_token before the JWT/auth middlewares
|
|
247
247
|
(0, auth_1.addAuthRoutes)(app, UserModel, options === null || options === void 0 ? void 0 : options.authOptions);
|
|
248
248
|
(0, auth_1.setupAuth)(app, UserModel);
|
package/dist/terrenoApp.js
CHANGED
|
@@ -205,7 +205,7 @@ var TerrenoApp = /** @class */ (function () {
|
|
|
205
205
|
var app = (0, express_1.default)();
|
|
206
206
|
var options = this.options;
|
|
207
207
|
app.set("query parser", function (str) { var _a; return qs_1.default.parse(str, { arrayLimit: (_a = options.arrayLimit) !== null && _a !== void 0 ? _a : 200 }); });
|
|
208
|
-
app.use((0, cors_1.default)({ origin: (_c = options.corsOrigin) !== null && _c !== void 0 ? _c : "*" }));
|
|
208
|
+
app.use((0, cors_1.default)({ credentials: true, origin: (_c = options.corsOrigin) !== null && _c !== void 0 ? _c : "*" }));
|
|
209
209
|
try {
|
|
210
210
|
// Apply custom middleware before JSON parsing
|
|
211
211
|
for (var _d = __values(this.middlewareFns), _e = _d.next(); !_e.done; _e = _d.next()) {
|
package/package.json
CHANGED
package/src/auth.ts
CHANGED
|
@@ -44,11 +44,17 @@ export function authenticateMiddleware(anonymous = false) {
|
|
|
44
44
|
if (anonymous) {
|
|
45
45
|
strategies.push("anonymous");
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
const passportAuth = passport.authenticate(strategies, {
|
|
48
48
|
failureMessage: false, // this is just avoiding storing the message in the session
|
|
49
49
|
failWithError: true,
|
|
50
50
|
session: false,
|
|
51
51
|
});
|
|
52
|
+
return (req: any, res: any, next: any) => {
|
|
53
|
+
if (req.user) {
|
|
54
|
+
return next();
|
|
55
|
+
}
|
|
56
|
+
return passportAuth(req, res, next);
|
|
57
|
+
};
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
export async function signupUser(
|
package/src/betterAuthSetup.ts
CHANGED
|
@@ -175,8 +175,10 @@ export const syncBetterAuthUser = async (
|
|
|
175
175
|
return userByEmail;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
//
|
|
178
|
+
// Use Better Auth ID as _id when it's a valid ObjectId (MongoDB adapter) so frontend IDs match
|
|
179
|
+
const useAsId = mongoose.isValidObjectId(betterAuthUser.id) ? {_id: betterAuthUser.id} : {};
|
|
179
180
|
const newUser: any = new (userModel as any)({
|
|
181
|
+
...useAsId,
|
|
180
182
|
admin: false,
|
|
181
183
|
betterAuthId: betterAuthUser.id,
|
|
182
184
|
email: betterAuthUser.email,
|
package/src/expressServer.ts
CHANGED
|
@@ -193,7 +193,7 @@ function initializeRoutes(
|
|
|
193
193
|
options.addMiddleware(app);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
app.use(express.json());
|
|
196
|
+
app.use(express.json({limit: "50mb"}));
|
|
197
197
|
|
|
198
198
|
// Add login/signup/refresh_token before the JWT/auth middlewares
|
|
199
199
|
addAuthRoutes(app, UserModel as any, options?.authOptions);
|
package/src/terrenoApp.ts
CHANGED
|
@@ -204,7 +204,7 @@ export class TerrenoApp {
|
|
|
204
204
|
qs.parse(str, {arrayLimit: options.arrayLimit ?? 200})
|
|
205
205
|
);
|
|
206
206
|
|
|
207
|
-
app.use(cors({origin: options.corsOrigin ?? "*"}));
|
|
207
|
+
app.use(cors({credentials: true, origin: options.corsOrigin ?? "*"}));
|
|
208
208
|
|
|
209
209
|
// Apply custom middleware before JSON parsing
|
|
210
210
|
for (const fn of this.middlewareFns) {
|