feat: token 改为多端会话,各端登录互不覆盖
This commit is contained in:
@@ -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' },
|
||||
|
||||
Reference in New Issue
Block a user