feat: 更新版本至 0.0.57,导出 User 类型并优化 beforeSetLoginUser 方法

This commit is contained in:
2026-02-21 04:33:19 +08:00
parent c97e246ba7
commit 3f8b9c2c4a
3 changed files with 10 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/api",
"version": "0.0.56",
"version": "0.0.57",
"description": "",
"main": "mod.ts",
"scripts": {

View File

@@ -16,7 +16,7 @@ export interface Cache {
*/
init?: () => Promise<any>;
}
type User = {
export type User = {
avatar?: string;
description?: string;
id?: string;

View File

@@ -1,6 +1,6 @@
import { Query, BaseQuery } from '@kevisual/query';
import type { Result, DataOpts } from '@kevisual/query/query';
import { LoginCacheStore, CacheStore } from './login-cache.ts';
import { LoginCacheStore, CacheStore, User } from './login-cache.ts';
import { Cache } from './login-cache.ts';
import { BaseLoad } from '@kevisual/load';
export type QueryLoginOpts<T extends Cache = Cache> = {
@@ -128,7 +128,8 @@ export class QueryLogin<T extends Cache = Cache> extends BaseQuery {
* 登陆成功,需要获取用户信息进行缓存
* @param param0
*/
async beforeSetLoginUser({ accessToken, refreshToken, check401, accessTokenExpiresIn }: { accessTokenExpiresIn?: number, accessToken?: string; refreshToken?: string; check401?: boolean }) {
async beforeSetLoginUser(opts: { accessTokenExpiresIn?: number, accessToken?: string; refreshToken?: string; check401?: boolean }): Promise<Result<User>> {
const { accessToken, refreshToken, check401, accessTokenExpiresIn } = opts;
if (accessToken && refreshToken) {
const resUser = await this.getMe(accessToken, check401);
if (resUser.code === 200) {
@@ -146,7 +147,12 @@ export class QueryLogin<T extends Cache = Cache> extends BaseQuery {
console.error('登录失败');
}
}
return resUser;
}
return {
code: 400,
message: '登录失败',
};
}
/**
* 刷新token