feat: token 改为多端会话,各端登录互不覆盖

This commit is contained in:
lik
2026-11-10 15:57:53 +08:00
parent d7d12bb19a
commit 5fabb6ba86
4 changed files with 181 additions and 17 deletions
+11
View File
@@ -31,6 +31,17 @@ const UserSchema = mongoose.Schema(
passwdSalt: { type: String, comment: '密码盐值' },
token: { type: String, index: true, sparse: true, comment: '认证令牌' },
tokenExpiry: { type: Date, comment: '令牌过期时间' },
// 多端会话:每次登录追加一条(只存哈希),各端互不覆盖;
// token/tokenExpiry 保留为最新会话的镜像,兼容仍读旧字段的客户端
tokens: [
{
_id: false,
hash: { type: String, index: true, sparse: true, comment: '令牌哈希' },
expiry: { type: Date, comment: '过期时间' },
appId: { type: String, default: '', comment: '登录来源应用' },
createdAt: { type: Date, default: Date.now, comment: '签发时间' },
},
],
failedLoginAttempts: { type: Number, default: 0, comment: '失败登录尝试次数' },
lastLoginAt: { type: Date, comment: '最后登录时间' },
lastLoginIp: { type: String, comment: '最后登录IP' },