diff --git a/packages/backend/src/misc/secure-rndstr.ts b/packages/backend/src/misc/secure-rndstr.ts deleted file mode 100644 index 966e8756..00000000 --- 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 5a8b41b7..7b23e682 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 e32edf12..c78ef88a 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 088de786..c92c97aa 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 bca09d3f..a673b6dc 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();