feat(auth): 微信登录自动分配 patient 角色 + 创建患者档案
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- 新增迁移 m20260510_000133:为所有租户创建 patient 角色并分配 19 个权限
- wechat_service: bind_phone 自动 assign_patient_role + ensure_patient_record
- find_or_create_user_by_phone 新用户自动获得 patient 角色和患者档案
- 小程序 auth store: bindPhone 抛出异常而非静默返回 false
- 小程序登录页: 捕获绑定错误并显示可操作的对话框
This commit is contained in:
iven
2026-05-10 09:57:45 +08:00
parent 28bcdc4208
commit 11101ac204
5 changed files with 238 additions and 12 deletions

View File

@@ -114,7 +114,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
const openid = secureGet('wechat_openid') || '';
if (!openid) {
set({ loading: false });
return false;
throw new Error('登录态丢失,请返回重试');
}
const resp = await authApi.wechatBindPhone(openid, encryptedData, iv) as Record<string, unknown>;
const tokenData = resp as { access_token: string; refresh_token: string; user: AuthState['user'] };
@@ -129,9 +129,10 @@ export const useAuthStore = create<AuthState>((set, get) => ({
secureRemove('wechat_openid');
set({ user: tokenData.user, roles, loading: false });
return true;
} catch {
} catch (err: any) {
secureRemove('wechat_openid');
set({ loading: false });
return false;
throw err;
}
},