From 4e63873fc114284585e2a94eaba7d4c96fac3026 Mon Sep 17 00:00:00 2001 From: naskya Date: Sun, 14 Jan 2024 12:24:29 +0900 Subject: [PATCH] refactor: remove misc/secure-rndstr.ts --- packages/backend/src/misc/secure-rndstr.ts | 5 ----- .../src/server/api/common/generate-native-user-token.ts | 4 ++-- packages/backend/src/server/api/endpoints/app/create.ts | 4 ++-- packages/backend/src/server/api/endpoints/auth/accept.ts | 6 +++--- .../backend/src/server/api/endpoints/miauth/gen-token.ts | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) delete mode 100644 packages/backend/src/misc/secure-rndstr.ts diff --git a/packages/backend/src/misc/secure-rndstr.ts b/packages/backend/src/misc/secure-rndstr.ts deleted file mode 100644 index 966e8756b..000000000 --- a/packages/backend/src/misc/secure-rndstr.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { genString } from "native-utils/built/index.js"; - -export function secureRndstr(length = 32, _ = true): string { - return genString(length); -} diff --git a/packages/backend/src/server/api/common/generate-native-user-token.ts b/packages/backend/src/server/api/common/generate-native-user-token.ts index 5a8b41b70..7b23e682e 100644 --- a/packages/backend/src/server/api/common/generate-native-user-token.ts +++ b/packages/backend/src/server/api/common/generate-native-user-token.ts @@ -1,3 +1,3 @@ -import { secureRndstr } from "@/misc/secure-rndstr.js"; +import { genString } from "native-utils/built/index.js"; -export default () => secureRndstr(16, true); +export default () => genString(16); diff --git a/packages/backend/src/server/api/endpoints/app/create.ts b/packages/backend/src/server/api/endpoints/app/create.ts index e32edf129..c78ef88aa 100644 --- a/packages/backend/src/server/api/endpoints/app/create.ts +++ b/packages/backend/src/server/api/endpoints/app/create.ts @@ -2,7 +2,7 @@ import define from "@/server/api/define.js"; import { Apps } from "@/models/index.js"; import { genId } from "@/misc/gen-id.js"; import { unique } from "@/prelude/array.js"; -import { secureRndstr } from "@/misc/secure-rndstr.js"; +import { genString } from "native-utils/built/index.js"; export const meta = { tags: ["app"], @@ -41,7 +41,7 @@ export default define(meta, paramDef, async (ps, user) => { includeSecret: true, }); // Generate secret - const secret = secureRndstr(32, true); + const secret = genString(32); // for backward compatibility const permission = unique( diff --git a/packages/backend/src/server/api/endpoints/auth/accept.ts b/packages/backend/src/server/api/endpoints/auth/accept.ts index 088de7863..c92c97aae 100644 --- a/packages/backend/src/server/api/endpoints/auth/accept.ts +++ b/packages/backend/src/server/api/endpoints/auth/accept.ts @@ -3,7 +3,7 @@ import define from "@/server/api/define.js"; import { ApiError } from "@/server/api/error.js"; import { AuthSessions, AccessTokens, Apps } from "@/models/index.js"; import { genId } from "@/misc/gen-id.js"; -import { secureRndstr } from "@/misc/secure-rndstr.js"; +import { genString } from "native-utils/built/index.js"; export const meta = { tags: ["auth"], @@ -38,10 +38,10 @@ export default define(meta, paramDef, async (ps, user) => { } // Generate access token - const accessToken = secureRndstr(32, true); + const accessToken = genString(32); // Fetch exist access token - const exist = await AccessTokens.exist({ + const exist = await AccessTokens.exists({ where: { appId: session.appId, userId: user.id, diff --git a/packages/backend/src/server/api/endpoints/miauth/gen-token.ts b/packages/backend/src/server/api/endpoints/miauth/gen-token.ts index bca09d3f0..a673b6dc2 100644 --- a/packages/backend/src/server/api/endpoints/miauth/gen-token.ts +++ b/packages/backend/src/server/api/endpoints/miauth/gen-token.ts @@ -1,7 +1,7 @@ import define from "@/server/api/define.js"; import { AccessTokens } from "@/models/index.js"; import { genId } from "@/misc/gen-id.js"; -import { secureRndstr } from "@/misc/secure-rndstr.js"; +import { genString } from "native-utils/built/index.js"; export const meta = { tags: ["auth"], @@ -44,7 +44,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, user) => { // Generate access token - const accessToken = secureRndstr(32, true); + const accessToken = genString(32); const now = new Date();