Compare commits
2 Commits
f8af24506b
...
557cd99b20
| Author | SHA1 | Date | |
|---|---|---|---|
| 557cd99b20 | |||
| 8b4312782d |
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/query-login",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.5",
|
||||
"description": "",
|
||||
"main": "dist/query-login.js",
|
||||
"types": "dist/query-login.d.ts",
|
||||
@@ -18,10 +18,10 @@
|
||||
"access": "public"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@kevisual/query": "^0.0.15"
|
||||
"@kevisual/query": "^0.0.17"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.11",
|
||||
"@types/node": "^22.14.1",
|
||||
"tsup": "^8.4.0"
|
||||
},
|
||||
"exports": {
|
||||
@@ -31,7 +31,7 @@
|
||||
"./browser": "./dist/query-login-browser.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kevisual/cache": "^0.0.1",
|
||||
"dotenv": "^16.4.7"
|
||||
"@kevisual/cache": "^0.0.2",
|
||||
"dotenv": "^16.5.0"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Query } from '@kevisual/query';
|
||||
import { Query, BaseQuery } from '@kevisual/query';
|
||||
import type { Result, DataOpts } from '@kevisual/query/query';
|
||||
import { setBaseResponse } from '@kevisual/query/query';
|
||||
import { LoginCacheStore, CacheStore } from './login-cache.ts';
|
||||
@@ -21,8 +21,7 @@ export type QueryLoginResult = {
|
||||
refreshToken: string;
|
||||
};
|
||||
|
||||
export class QueryLogin {
|
||||
query: Query;
|
||||
export class QueryLogin extends BaseQuery {
|
||||
/**
|
||||
* query login cache, 非实际操作, 一个cache的包裹模块
|
||||
*/
|
||||
@@ -33,7 +32,9 @@ export class QueryLogin {
|
||||
onLoad?: () => void;
|
||||
|
||||
constructor(opts?: QueryLoginOpts) {
|
||||
this.query = opts?.query || new Query();
|
||||
super({
|
||||
query: opts?.query || new Query(),
|
||||
});
|
||||
this.cacheStore = new LoginCacheStore({ name: 'login', cache: opts.cache });
|
||||
this.isBrowser = opts?.isBrowser ?? true;
|
||||
this.init();
|
||||
@@ -274,6 +275,25 @@ export class QueryLogin {
|
||||
},
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 检查本地用户,如果本地用户存在,则返回本地用户,否则返回null
|
||||
* @returns
|
||||
*/
|
||||
async checkLocalUser() {
|
||||
const user = await this.cacheStore.getCurrentUser();
|
||||
if (user) {
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 检查本地token是否存在,简单的判断是否已经属于登陆状态
|
||||
* @returns
|
||||
*/
|
||||
async checkLocalToken() {
|
||||
const token = this.storage.getItem('token');
|
||||
return !!token;
|
||||
}
|
||||
/**
|
||||
* 请求更新,切换用户, 使用switchUser
|
||||
* @param username
|
||||
|
||||
Reference in New Issue
Block a user