feat: 更新命令脚本名称,添加 CLI 入口文件,优化用户验证逻辑

This commit is contained in:
2026-03-31 02:05:01 +08:00
parent 5c981f25a7
commit 2fd473a1b1
5 changed files with 11 additions and 3 deletions

View File

@@ -16,7 +16,7 @@
},
"scripts": {
"dev": "bun run --watch --hot src/index.ts",
"cmd": "bun run src/run.ts ",
"cli": "bun run src/cli.ts ",
"prebuild": "rimraf dist && rimraf pack-dist",
"build": "NODE_ENV=production bun bun.config.mjs",
"postbuild": "ev pack",

View File

@@ -166,7 +166,6 @@ export class RedisTokenStore implements Store<OauthUser> {
} else {
expire = Math.min(expire, 60 * 60 * 24 * 30); // 默认的过期时间最大为30天
}
await this.set(accessToken, JSON.stringify(value), expire);
await this.set(userPrefix + ':token:' + accessToken, accessToken, expire);
// refreshToken的过期时间比accessToken多expireDay天确保在accessToken过期后refreshToken仍然有效

8
src/cli.ts Normal file
View File

@@ -0,0 +1,8 @@
import { parse } from '@kevisual/router/commander'
import { app } from './app.ts';
import './route.ts';
parse({
app,
})

View File

@@ -52,6 +52,7 @@ export const getLoginUserByToken = async (token: string) => {
let tokenUser;
try {
tokenUser = await User.verifyToken(token);
if (!tokenUser) return null;
return { tokenUser, token };
} catch (e) {
return null;
@@ -66,6 +67,7 @@ export const getLoginUser = async (req: http.IncomingMessage) => {
logger.debug('getLoginUser', token);
try {
tokenUser = await User.verifyToken(token);
if (!tokenUser) return null;
return { tokenUser, token };
} catch (e) {
return null;

View File

@@ -26,7 +26,6 @@ export const wssFun: WebSocketListenerFun = async (req, res) => {
}
if (!user) {
logger.debug('未提供用户名,无法注册 ws 连接');
ws.close();
return;
}
let userApp = user + '--' + id;