feat(auth): rich workspace-aware notification on successful login

Replace the plain "Login successful" toast with a TDesign Notify card
that surfaces the workspace the user just landed in and their role
there, so users immediately see which space they're working in —
especially useful now that login can drop them into a remembered
non-home tenant.

A small shared helper (utils/loginNotify.ts) handles both the password
login path (views/auth/Login.vue) and the OIDC callback path
(App.vue handleGlobalOIDCCallback), so the two flows stay consistent.
Role label goes through the same useRoleLabel composable used by the
rest of the role-aware UI, so locale + future role-name tweaks live in
one place. The membership lookup falls back gracefully (no role line)
when the active tenant isn't in the response's memberships list — e.g.
the auto-setup path that synthesises a single owner row.

The legacy auth.loginSuccess key is left in place; nothing else
references it, so a future cleanup PR can drop it safely.
This commit is contained in:
wizardchen
2026-05-18 20:21:46 +08:00
committed by lyingbug
parent 0cdb922d84
commit 60a579d869
7 changed files with 67 additions and 2 deletions
+47
View File
@@ -0,0 +1,47 @@
// Rich "you're now in {workspace} as {role}" notification for the
// post-login moment. Shared between the password (views/auth/Login.vue)
// and OIDC (App.vue handleGlobalOIDCCallback) login paths so the two
// flows feel identical to the user.
//
// Kept as a free function — not a composable — because the caller
// already has `t` and `formatRole` in scope from useI18n / useRoleLabel
// and there is no per-instance state worth tracking.
import { NotifyPlugin } from 'tdesign-vue-next'
type Translator = (key: string, params?: Record<string, unknown>) => string
type RoleFormatter = (role: string | null | undefined) => string
interface LoginResponseLike {
// Password-login response uses `active_tenant`; the OIDC callback
// response uses `tenant` (legacy backward-compat name on the Go side).
// Accept either so callers don't have to normalise.
active_tenant?: { id?: number | string; name?: string }
tenant?: { id?: number | string; name?: string }
memberships?: Array<{ tenant_id?: number | string; role?: string }>
}
export function notifyLoginSuccess(
response: LoginResponseLike | null | undefined,
t: Translator,
formatRole: RoleFormatter,
): void {
const activeTenant = response?.active_tenant || response?.tenant
if (!activeTenant) return
const tenantName = activeTenant.name || String(activeTenant.id || '')
const activeTenantId = Number(activeTenant.id)
const membership = Array.isArray(response?.memberships)
? response!.memberships!.find((m) => Number(m?.tenant_id) === activeTenantId)
: null
const roleLabel = membership?.role ? formatRole(membership.role) : ''
NotifyPlugin.success({
title: t('auth.loginSuccessTitle'),
content: roleLabel
? t('auth.loginSuccessContentWithRole', { name: tenantName, role: roleLabel })
: t('auth.loginSuccessContent', { name: tenantName }),
duration: 6000,
closeBtn: true,
})
}