diff --git a/src/http/middleware/authorization.ts b/src/http/middleware/authorization.ts index 001268c..f975d81 100644 --- a/src/http/middleware/authorization.ts +++ b/src/http/middleware/authorization.ts @@ -18,25 +18,7 @@ export const authMiddleware = createMiddleware(async (ctx, next) => { return errorThrow(ErrorCode.Validation, token.summary); } - const dotIndex = token.indexOf("."); - if (dotIndex === -1) { - // unhashed token - if (token.length === 32) { - // @ts-expect-error unindexed select - const id = mutableDatabase.user.get("token", token)?.id; - if (!id) { - return errorThrow(ErrorCode.UserInvalidToken); - } - - ctx.set("userId", id); - - return next(); - } - - return errorThrow(ErrorCode.UserInvalidToken); - } - - const id = token.slice(0, dotIndex); + const id = token.slice(0, token.indexOf(".")); if (!id) { return errorThrow(ErrorCode.UserInvalidToken); } diff --git a/src/init.ts b/src/init.ts index 73f7e85..e82464d 100644 --- a/src/init.ts +++ b/src/init.ts @@ -89,10 +89,6 @@ export const initUnhashedTokenCheck = (): void => { } if (userUnhashedToken) { - log.warn( - "Users with unhashed tokens found!", - "Those users may lose access in future versions of JSPaste!", - "See: https://github.com/jspaste/backend/issues/318" - ); + log.error("Users with unhashed tokens found!", "See: https://github.com/jspaste/backend/issues/318"); } }; diff --git a/src/utils/validator/document.ts b/src/utils/validator/document.ts index 4926444..41a2761 100644 --- a/src/utils/validator/document.ts +++ b/src/utils/validator/document.ts @@ -84,8 +84,6 @@ export const validatorDocumentListObject = type({ name: validatorDocumentName, created: validatorCreationTimestamp }).configure({ - // FIXME: schema references not being generated when using toOpenAPISchema() - // Invalid object key "DocumentListMetadata" at position 2 in "/components/schemas/DocumentListMetadata": key not found in object - //ref: "DocumentListMetadata", + ref: "DocumentListObject", description: "An object with document metadata" }); diff --git a/src/utils/validator/user.ts b/src/utils/validator/user.ts index 3ad1d67..9ebb0fb 100644 --- a/src/utils/validator/user.ts +++ b/src/utils/validator/user.ts @@ -2,11 +2,10 @@ import { type } from "arktype"; import { constantUserTokenLength } from "#/global.ts"; -import { regexBase64URL, regexHeaderBearer } from "../regex.ts"; +import { regexHeaderBearer } from "../regex.ts"; -// FIXME: schema references not being generated when using toOpenAPISchema() export const validatorUserToken = type.string.exactlyLength(constantUserTokenLength).configure({ - ref: "UserToken.default", + ref: "UserToken", description: "A user token", examples: ["myUserTokenHere"], expected: (ctx) => { @@ -25,31 +24,9 @@ export const validatorUserToken = type.string.exactlyLength(constantUserTokenLen } }); -export const validatorUserTokenLegacy = type(regexBase64URL) - .exactlyLength(32) - .configure({ - ref: "UserToken.legacy", - description: "An unhashed user token", - examples: ["myUserTokenHere"], - expected: (ctx) => { - // oxlint-disable-next-line typescript-eslint/switch-exhaustiveness-check - switch (ctx.code) { - case "pattern": { - return "a valid Base64URL"; - } - case "exactLength": { - return `exactly ${ctx.rule} characters`; - } - default: { - return "valid"; - } - } - } - }); - export const validatorUserHeader = type(regexHeaderBearer) .configure({ description: "A RFC 6750 structured Bearer header", expected: "a valid header" }) - .pipe((string) => string.split(" ")[1], validatorUserToken.or(validatorUserTokenLegacy)); + .pipe((string) => string.split(" ")[1], validatorUserToken);