@@ -9,6 +9,8 @@ export type ShopAccountProfile = {
|
||||
storeId: string;
|
||||
name: string;
|
||||
phone: string;
|
||||
/** 是否已绑定微信(来自 /shop/auth/me account.hasWechat) */
|
||||
hasWechat?: boolean;
|
||||
wxOpenId?: string | null;
|
||||
store?: { name: string };
|
||||
};
|
||||
@@ -18,7 +20,27 @@ export async function fetchClientConfig(): Promise<ClientRuntimeConfig> {
|
||||
}
|
||||
|
||||
export async function fetchShopAccount(): Promise<ShopAccountProfile> {
|
||||
return request<ShopAccountProfile>('SHOP_H5', '/shop/auth/me');
|
||||
const me = await request<{
|
||||
id?: string;
|
||||
storeId?: string;
|
||||
name?: string;
|
||||
phone?: string;
|
||||
account?: {
|
||||
id?: string;
|
||||
name?: string;
|
||||
phone?: string;
|
||||
hasWechat?: boolean;
|
||||
};
|
||||
store?: { name?: string } | null;
|
||||
}>('SHOP_H5', '/shop/auth/me');
|
||||
return {
|
||||
id: String(me.account?.id ?? me.id ?? ''),
|
||||
storeId: String(me.storeId ?? ''),
|
||||
name: String(me.account?.name ?? me.name ?? ''),
|
||||
phone: String(me.account?.phone ?? me.phone ?? ''),
|
||||
hasWechat: !!me.account?.hasWechat,
|
||||
store: me.store?.name ? { name: String(me.store.name) } : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function needsWechatAuth(
|
||||
@@ -26,7 +48,8 @@ export function needsWechatAuth(
|
||||
config?: Pick<ClientRuntimeConfig, 'wxAuthorize'> | null,
|
||||
): boolean {
|
||||
if (config && !isWxAuthorizeEnabled(config)) return false;
|
||||
return isWechatEnv() && !!profile && !profile.wxOpenId;
|
||||
const unbound = !!profile && !(profile.hasWechat || profile.wxOpenId);
|
||||
return isWechatEnv() && unbound;
|
||||
}
|
||||
|
||||
export async function checkNeedsWechatAuth(profile: ShopAccountProfile | null): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user