Files
wzdj/scripts/set-user-password.ts
卡若 b95d1a94c6 feat(live): 直播与主播工作台 API、云厂商解析与文档调研
- 新增直播评论/上下文/礼物等 API 与回放组件
- 主播开播、云端推流配置与 streamer 校验
- 依赖与 Mongo 集合/种子更新
- 需求与调研文档补充

Made-with: Cursor
2026-04-14 16:24:17 +08:00

49 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 重置指定手机号的登录密码userAuths.credential
* 用法pnpm exec tsx scripts/set-user-password.ts [手机号] [新密码]
* 默认15880802661 key123456
*/
import { config } from "dotenv"
import { resolve } from "path"
config({ path: resolve(process.cwd(), ".env.local") })
import { MongoClient } from "mongodb"
import { hashPassword } from "../lib/auth-utils"
import { COLLECTIONS } from "../lib/db/mongo/collections"
const phone = process.argv[2]?.trim() || "15880802661"
const newPassword = process.argv[3] || "key123456"
async function main() {
const uri = process.env.MONGODB_URI
if (!uri) {
console.error("缺少 MONGODB_URI请在 .env.local 配置")
process.exit(1)
}
const client = new MongoClient(uri)
await client.connect()
try {
const db = client.db("wanzhi_esports")
const auths = db.collection(COLLECTIONS.userAuths)
const hash = hashPassword(newPassword)
const r = await auths.updateOne(
{ authType: "phone", authId: phone },
{ $set: { credential: hash, updatedAt: new Date() } },
)
if (r.matchedCount === 0) {
console.error(`未找到手机号 ${phone} 的认证记录,请先注册或检查号码`)
process.exit(1)
}
console.log(`已更新 ${phone} 的登录密码(${newPassword.length} 位)`)
} finally {
await client.close()
}
}
main().catch((e) => {
console.error(e)
process.exit(1)
})