@semiont/backend 0.4.4 → 0.4.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/dist/index.js +35 -15
- package/dist/index.js.map +1 -1
- package/dist/openapi.json +6 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { SemiontProject, loadEnvironmentConfig } from '@semiont/core/node';
|
|
|
11
11
|
import { exportBackup, importBackup, readEntityTypesProjection, exportLinkedData, importLinkedData, AnnotationContext, startMakeMeaning, ResourceContext, ResourceOperations } from '@semiont/make-meaning';
|
|
12
12
|
import { PrismaClient } from '@prisma/client';
|
|
13
13
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
14
|
+
import { setCookie, deleteCookie, getCookie } from 'hono/cookie';
|
|
14
15
|
import { HTTPException } from 'hono/http-exception';
|
|
15
16
|
import Ajv from 'ajv';
|
|
16
17
|
import addFormats from 'ajv-formats';
|
|
@@ -15362,6 +15363,10 @@ var openapi_default = {
|
|
|
15362
15363
|
},
|
|
15363
15364
|
created: {
|
|
15364
15365
|
type: "string"
|
|
15366
|
+
},
|
|
15367
|
+
token: {
|
|
15368
|
+
type: "string",
|
|
15369
|
+
description: "The validated JWT token string for the current session"
|
|
15365
15370
|
}
|
|
15366
15371
|
},
|
|
15367
15372
|
required: [
|
|
@@ -15375,7 +15380,8 @@ var openapi_default = {
|
|
|
15375
15380
|
"isActive",
|
|
15376
15381
|
"termsAcceptedAt",
|
|
15377
15382
|
"lastLogin",
|
|
15378
|
-
"created"
|
|
15383
|
+
"created",
|
|
15384
|
+
"token"
|
|
15379
15385
|
]
|
|
15380
15386
|
},
|
|
15381
15387
|
SvgSelector: {
|
|
@@ -15846,22 +15852,16 @@ var OAuthService = class {
|
|
|
15846
15852
|
var authMiddleware = /* @__PURE__ */ __name(async (c, next) => {
|
|
15847
15853
|
const logger2 = c.get("logger");
|
|
15848
15854
|
const authHeader = c.req.header("Authorization");
|
|
15849
|
-
|
|
15850
|
-
|
|
15851
|
-
|
|
15852
|
-
|
|
15853
|
-
|
|
15854
|
-
method: c.req.method
|
|
15855
|
-
});
|
|
15856
|
-
return c.json({
|
|
15857
|
-
error: "Unauthorized"
|
|
15858
|
-
}, 401);
|
|
15855
|
+
let tokenStr;
|
|
15856
|
+
if (authHeader?.startsWith("Bearer ")) {
|
|
15857
|
+
tokenStr = authHeader.substring(7).trim();
|
|
15858
|
+
} else {
|
|
15859
|
+
tokenStr = getCookie(c, "semiont-token");
|
|
15859
15860
|
}
|
|
15860
|
-
const tokenStr = authHeader.substring(7).trim();
|
|
15861
15861
|
if (!tokenStr) {
|
|
15862
|
-
logger2.warn("Authentication failed:
|
|
15862
|
+
logger2.warn("Authentication failed: No token", {
|
|
15863
15863
|
type: "auth_failed",
|
|
15864
|
-
reason: "
|
|
15864
|
+
reason: "missing_token",
|
|
15865
15865
|
path: c.req.path,
|
|
15866
15866
|
method: c.req.method
|
|
15867
15867
|
});
|
|
@@ -15872,6 +15872,7 @@ var authMiddleware = /* @__PURE__ */ __name(async (c, next) => {
|
|
|
15872
15872
|
try {
|
|
15873
15873
|
const user = await OAuthService.getUserFromToken(accessToken(tokenStr));
|
|
15874
15874
|
c.set("user", user);
|
|
15875
|
+
c.set("token", tokenStr);
|
|
15875
15876
|
logger2.debug("Authentication successful", {
|
|
15876
15877
|
type: "auth_success",
|
|
15877
15878
|
userId: user.id,
|
|
@@ -16063,6 +16064,13 @@ authRouter.post("/api/tokens/password", validateRequestBody("PasswordAuthRequest
|
|
|
16063
16064
|
lastLogin: /* @__PURE__ */ new Date()
|
|
16064
16065
|
}
|
|
16065
16066
|
});
|
|
16067
|
+
setCookie(c, "semiont-token", token, {
|
|
16068
|
+
httpOnly: true,
|
|
16069
|
+
secure: process.env.NODE_ENV === "production",
|
|
16070
|
+
sameSite: "Lax",
|
|
16071
|
+
path: "/",
|
|
16072
|
+
maxAge: 7 * 24 * 60 * 60
|
|
16073
|
+
});
|
|
16066
16074
|
const response = {
|
|
16067
16075
|
success: true,
|
|
16068
16076
|
user: {
|
|
@@ -16098,6 +16106,13 @@ authRouter.post("/api/tokens/google", validateRequestBody("GoogleAuthRequest"),
|
|
|
16098
16106
|
}
|
|
16099
16107
|
const googleUser = await OAuthService.verifyGoogleToken(googleCredential(access_token));
|
|
16100
16108
|
const { user, token, isNewUser } = await OAuthService.createOrUpdateUser(googleUser);
|
|
16109
|
+
setCookie(c, "semiont-token", token, {
|
|
16110
|
+
httpOnly: true,
|
|
16111
|
+
secure: process.env.NODE_ENV === "production",
|
|
16112
|
+
sameSite: "Lax",
|
|
16113
|
+
path: "/",
|
|
16114
|
+
maxAge: 7 * 24 * 60 * 60
|
|
16115
|
+
});
|
|
16101
16116
|
const response = {
|
|
16102
16117
|
success: true,
|
|
16103
16118
|
user: {
|
|
@@ -16194,6 +16209,7 @@ authRouter.post("/api/tokens/refresh", validateRequestBody("TokenRefreshRequest"
|
|
|
16194
16209
|
});
|
|
16195
16210
|
authRouter.get("/api/users/me", authMiddleware, async (c) => {
|
|
16196
16211
|
const user = c.get("user");
|
|
16212
|
+
const token = c.get("token");
|
|
16197
16213
|
const response = {
|
|
16198
16214
|
id: user.id,
|
|
16199
16215
|
email: user.email,
|
|
@@ -16205,7 +16221,8 @@ authRouter.get("/api/users/me", authMiddleware, async (c) => {
|
|
|
16205
16221
|
isActive: user.isActive,
|
|
16206
16222
|
termsAcceptedAt: user.termsAcceptedAt?.toISOString() || null,
|
|
16207
16223
|
lastLogin: user.lastLogin?.toISOString() || null,
|
|
16208
|
-
created: user.createdAt.toISOString()
|
|
16224
|
+
created: user.createdAt.toISOString(),
|
|
16225
|
+
token
|
|
16209
16226
|
};
|
|
16210
16227
|
return c.json(response, 200);
|
|
16211
16228
|
});
|
|
@@ -16247,6 +16264,9 @@ authRouter.post("/api/users/accept-terms", authMiddleware, async (c) => {
|
|
|
16247
16264
|
return c.json(response, 200);
|
|
16248
16265
|
});
|
|
16249
16266
|
authRouter.post("/api/users/logout", authMiddleware, async (c) => {
|
|
16267
|
+
deleteCookie(c, "semiont-token", {
|
|
16268
|
+
path: "/"
|
|
16269
|
+
});
|
|
16250
16270
|
return c.json({
|
|
16251
16271
|
success: true,
|
|
16252
16272
|
message: "Logged out successfully"
|