security: access control for particles (#169)
* setup firebase custom token * docs * docs * feat: allow admin removing members from a network * fix: properly handle fallback avatar and names This is especially helpful in the case of members who were removed from a network
This commit was merged in pull request #169.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import type { Human } from "@/api/types";
|
||||
import { getInitials } from "@/lib/utils";
|
||||
|
||||
export const REMOVED_MEMBER_LABEL = "Removed member";
|
||||
export const REMOVED_MEMBER_INITIALS = "–";
|
||||
|
||||
export interface HumanDisplay {
|
||||
/** True when the human was found in the provided list. */
|
||||
exists: boolean;
|
||||
/** Short name for inline text (e.g. message sender). */
|
||||
displayName: string;
|
||||
/** Full email or fallback label for tooltips. */
|
||||
email: string;
|
||||
/** Initials for avatar fallback. */
|
||||
initials: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a human's display info by id, falling back consistently when the
|
||||
* human has been removed from the network. Member content (particles, reactions,
|
||||
* etc.) is retained after removal, so every render path needs a graceful fallback
|
||||
* instead of leaking raw ids into the UI.
|
||||
*/
|
||||
export function resolveHumanDisplay(
|
||||
humanId: string | null | undefined,
|
||||
humans: Human[] | undefined,
|
||||
): HumanDisplay {
|
||||
const human = humanId ? humans?.find((h) => h.id === humanId) : undefined;
|
||||
if (!human) {
|
||||
return {
|
||||
exists: false,
|
||||
displayName: REMOVED_MEMBER_LABEL,
|
||||
email: REMOVED_MEMBER_LABEL,
|
||||
initials: REMOVED_MEMBER_INITIALS,
|
||||
};
|
||||
}
|
||||
return {
|
||||
exists: true,
|
||||
displayName: human.email_prefix,
|
||||
email: human.email,
|
||||
initials: getInitials(human.email),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user