feat: add user login expire time

This commit is contained in:
2025-02-16 03:05:21 +08:00
parent 17322033ad
commit a52ae9ea3a
2 changed files with 12 additions and 9 deletions

View File

@@ -27,7 +27,7 @@ app
key: 'login',
})
.define(async (ctx) => {
const { username, email, password } = ctx.query;
const { username, email, password, loginType = 'default' } = ctx.query;
if (!username && !email) {
ctx.throw(400, 'username or email is required');
}
@@ -50,7 +50,7 @@ app
if (!user.checkPassword(password)) {
ctx.throw(500, 'Password error');
}
const token = await user.createToken();
const token = await user.createToken(null, loginType);
ctx.res.cookie('token', token.token, {
maxAge: token.expireTime,
domain: 'xiongxiao.me',
@@ -128,7 +128,7 @@ app
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { username, type = 'org' } = ctx.query.data || {};
const { username, type = 'org', loginType } = ctx.query.data || {};
if (!username && type === 'org') {
ctx.throw('username is required');
}
@@ -139,11 +139,11 @@ app
ctx.throw('user not found');
}
if (user.type === 'user') {
const token = await user.createToken();
const token = await user.createToken(null, loginType);
ctx.body = token;
return;
} else if (user.type === 'org' && tokenUser.uid) {
const token = await user.createToken(tokenUser.uid);
const token = await user.createToken(tokenUser.uid, loginType);
ctx.body = token;
return;
}
@@ -159,7 +159,7 @@ app
ctx.throw('Permission denied');
}
if (type === 'user') {
const token = await me.createToken();
const token = await me.createToken(null, loginType);
ctx.body = token;
return;
}
@@ -173,7 +173,7 @@ app
if (index === -1) {
ctx.throw('Permission denied');
}
const token = await orgUser.createToken(me.id);
const token = await orgUser.createToken(me.id, loginType);
ctx.body = token;
})
.addTo(app);