Compare commits
4 Commits
f8af24506b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bae8275b11 | |||
| 0a0ffbdb23 | |||
| 557cd99b20 | |||
| 8b4312782d |
65
.gitignore
vendored
65
.gitignore
vendored
@@ -1,5 +1,66 @@
|
|||||||
dist
|
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
# mac
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.env
|
|
||||||
|
.env*
|
||||||
|
!.env*example
|
||||||
|
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
logs
|
||||||
|
|
||||||
|
.turbo
|
||||||
|
|
||||||
|
pack-dist
|
||||||
|
|
||||||
|
# astro
|
||||||
|
.astro
|
||||||
|
|
||||||
|
# next
|
||||||
|
.next
|
||||||
|
|
||||||
|
# nuxt
|
||||||
|
.nuxt
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# vuepress
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# coverage
|
||||||
|
coverage/
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# debug logs
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
|
||||||
|
# vscode
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
|
||||||
|
# idea
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# system
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# temp files
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
|
||||||
|
# local development
|
||||||
|
*.local
|
||||||
|
|
||||||
|
public/r
|
||||||
|
|
||||||
|
.pnpm-store
|
||||||
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/query-login",
|
"name": "@kevisual/query-login",
|
||||||
"version": "0.0.3",
|
"version": "0.0.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/query-login.js",
|
"main": "dist/query-login.js",
|
||||||
"types": "dist/query-login.d.ts",
|
"types": "dist/query-login.d.ts",
|
||||||
@@ -18,10 +18,10 @@
|
|||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@kevisual/query": "^0.0.15"
|
"@kevisual/query": "^0.0.17"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.13.11",
|
"@types/node": "^22.14.1",
|
||||||
"tsup": "^8.4.0"
|
"tsup": "^8.4.0"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
"./browser": "./dist/query-login-browser.js"
|
"./browser": "./dist/query-login-browser.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kevisual/cache": "^0.0.1",
|
"@kevisual/cache": "^0.0.2",
|
||||||
"dotenv": "^16.4.7"
|
"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 type { Result, DataOpts } from '@kevisual/query/query';
|
||||||
import { setBaseResponse } from '@kevisual/query/query';
|
import { setBaseResponse } from '@kevisual/query/query';
|
||||||
import { LoginCacheStore, CacheStore } from './login-cache.ts';
|
import { LoginCacheStore, CacheStore } from './login-cache.ts';
|
||||||
@@ -21,8 +21,7 @@ export type QueryLoginResult = {
|
|||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class QueryLogin {
|
export class QueryLogin extends BaseQuery {
|
||||||
query: Query;
|
|
||||||
/**
|
/**
|
||||||
* query login cache, 非实际操作, 一个cache的包裹模块
|
* query login cache, 非实际操作, 一个cache的包裹模块
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +32,9 @@ export class QueryLogin {
|
|||||||
onLoad?: () => void;
|
onLoad?: () => void;
|
||||||
|
|
||||||
constructor(opts?: QueryLoginOpts) {
|
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.cacheStore = new LoginCacheStore({ name: 'login', cache: opts.cache });
|
||||||
this.isBrowser = opts?.isBrowser ?? true;
|
this.isBrowser = opts?.isBrowser ?? true;
|
||||||
this.init();
|
this.init();
|
||||||
@@ -86,6 +87,15 @@ export class QueryLogin {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 设置token
|
||||||
|
* @param token
|
||||||
|
*/
|
||||||
|
async setLoginToken(token: { accessToken: string; refreshToken: string }) {
|
||||||
|
const { accessToken, refreshToken } = token;
|
||||||
|
this.storage.setItem('token', accessToken || '');
|
||||||
|
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
||||||
|
}
|
||||||
async loginByWechat(data: { code: string }) {
|
async loginByWechat(data: { code: string }) {
|
||||||
const res = await this.post<QueryLoginResult>({ path: 'wx', key: 'open-login', code: data.code });
|
const res = await this.post<QueryLoginResult>({ path: 'wx', key: 'open-login', code: data.code });
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
@@ -274,6 +284,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
|
* 请求更新,切换用户, 使用switchUser
|
||||||
* @param username
|
* @param username
|
||||||
|
|||||||
Reference in New Issue
Block a user