feat: 更新版本至 0.0.57,导出 User 类型并优化 beforeSetLoginUser 方法
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/api",
|
"name": "@kevisual/api",
|
||||||
"version": "0.0.56",
|
"version": "0.0.57",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "mod.ts",
|
"main": "mod.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export interface Cache {
|
|||||||
*/
|
*/
|
||||||
init?: () => Promise<any>;
|
init?: () => Promise<any>;
|
||||||
}
|
}
|
||||||
type User = {
|
export type User = {
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
id?: string;
|
id?: string;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Query, BaseQuery } from '@kevisual/query';
|
import { Query, BaseQuery } from '@kevisual/query';
|
||||||
import type { Result, DataOpts } from '@kevisual/query/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 { Cache } from './login-cache.ts';
|
||||||
import { BaseLoad } from '@kevisual/load';
|
import { BaseLoad } from '@kevisual/load';
|
||||||
export type QueryLoginOpts<T extends Cache = Cache> = {
|
export type QueryLoginOpts<T extends Cache = Cache> = {
|
||||||
@@ -128,7 +128,8 @@ export class QueryLogin<T extends Cache = Cache> extends BaseQuery {
|
|||||||
* 登陆成功,需要获取用户信息进行缓存
|
* 登陆成功,需要获取用户信息进行缓存
|
||||||
* @param param0
|
* @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) {
|
if (accessToken && refreshToken) {
|
||||||
const resUser = await this.getMe(accessToken, check401);
|
const resUser = await this.getMe(accessToken, check401);
|
||||||
if (resUser.code === 200) {
|
if (resUser.code === 200) {
|
||||||
@@ -146,7 +147,12 @@ export class QueryLogin<T extends Cache = Cache> extends BaseQuery {
|
|||||||
console.error('登录失败');
|
console.error('登录失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return resUser;
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
code: 400,
|
||||||
|
message: '登录失败',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 刷新token
|
* 刷新token
|
||||||
|
|||||||
Reference in New Issue
Block a user