This commit is contained in:
2025-12-04 10:05:03 +08:00
parent 9dfb3f4160
commit 4d22797cb9
4 changed files with 436 additions and 506 deletions

View File

@@ -9,7 +9,7 @@ import { checkAuth, getLoginUser } from './middleware/auth-manual.ts';
export { User, Org, UserServices, UserInit, OrgInit, UserModel, OrgModel, UserSecret, UserSecretInit };
/**
* 可以不需要user成功, 有则赋值,交给下一个中间件
* 可以不需要user成功, 有则赋值,没有则无所谓,交给下一个中间件
*/
export const authCan = 'auth-can';
/**

View File

@@ -8,6 +8,23 @@ import { OauthUser } from '@/oauth/oauth.ts';
export const redis = useContextKey<Redis>('redis');
const UserSecretStatus = ['active', 'inactive', 'expired'] as const;
type Data = {
[key: string]: any;
/**
* 微信开放平台的某一个应用的openid
*/
wxOpenid?: string;
/**
* 微信开放平台的unionid主要
*/
wxUnionid?: string;
/**
* 微信公众号的openid次要
*/
wxmpOpenid?: string;
}
export class UserSecret extends Model {
static oauth = oauth;
declare id: string;
@@ -18,7 +35,7 @@ export class UserSecret extends Model {
declare description: string;
declare status: (typeof UserSecretStatus)[number];
declare expiredTime: Date;
declare data: any;
declare data: Data;
/**
* 验证token
* @param token
@@ -44,9 +61,6 @@ export class UserSecret extends Model {
if (userSecret.status !== 'active') {
return null; // 如果用户密钥状态不是active则返回null
}
if (!userSecret.token) {
return null; // 如果用户密钥没有token则返回null
}
// 如果用户密钥未过期,则返回用户信息
const oauthUser = await userSecret.getOauthUser();
if (!oauthUser) {