Skip to content

WhoAmI ​

When the person accepts your view in the webapp they always share their nickname with it. They can also tick the public fields of their profile that the view may see. WhoAmI renders the nickname followed by the full name, the organization and the place of the person when they shared them. Put it in a corner of the view to show the person what the view knows about them or use it as the start of your own profile panel.

jsx
import { useWorld } from './useWorld.js';

// The component: copy this part.

/**
 * Makes the lines that say who the person is, from what they shared: their
 * full name, their organization, and where they live. A line is left out
 * when the person did not share any of its fields.
 * @param {object|undefined} me - The person, from `world.me`.
 * @returns {string[]} The lines, in order.
 */
function linesOf(me) {
	const fullName = [me?.title, me?.name, me?.surname].filter(Boolean).join(' ');
	const place = [me?.city, me?.country].filter(Boolean).join(', ');
	return [fullName, me?.organization, place].filter(Boolean);
}

/**
 * WhoAmI: who the person is, from what they chose to share with your view
 * when they accepted it in the webapp: their nickname and the profile fields
 * they ticked. Your view gets nothing else about them.
 * @param {object} props
 * @param {object} props.world - The world, from useWorld.
 */
export function WhoAmI({ world }) {
	// `me` holds the nickname, always, and only the fields the person ticked.
	// It is missing with a webapp older than this kit.
	const me = world.me;
	const lines = linesOf(me);
	let note = 'What you chose to share with this view.';
	if (!me) note = 'This webapp does not say who you are.';
	else if (lines.length === 0) note = 'You shared only your nickname with this view.';

	return (
		<section aria-label="Who you are" style={{ display: 'grid', gap: 4, padding: 16, borderRadius: 14, border: '1px solid rgba(127, 127, 127, 0.3)' }}>
			<strong style={{ fontSize: 18 }}>{me?.nickname ?? 'Guest'}</strong>
			<div style={{ display: 'grid', gap: 2 }}>
				{lines.map((text) => <span key={text}>{text}</span>)}
			</div>
			<small style={{ opacity: 0.75 }}>{note}</small>
		</section>
	);
}

// Using it, on a fake world.

// A fake world to build with. Its `me` is the person as the webapp would give them, with the fields they ticked.
const rowing = {
	name: 'Rowing club',
	me: { nickname: 'ada', name: 'Ada', surname: 'Rossi', organization: 'Siena Rowing Club', city: 'Siena', country: 'Italy' },
};

export default function App() {
	// While building: the fake world. In the webapp: useWorld()
	const { world, error } = useWorld({ fake: { world: rowing } });

	if (error) return <p>Could not connect ({error.code}).</p>;
	if (!world) return <p>Connecting…</p>;
	return (
		<div style={{ display: 'grid', gap: 12, maxWidth: 420 }}>
			<h2 style={{ margin: 0 }}>{world.name}</h2>
			<WhoAmI world={world} />
		</div>
	);
}
js
import { connectToHost } from '@unaiverse/gui-kit';

// The component: copy this part.

/**
 * Makes the lines that say who the person is, from what they shared: their
 * full name, their organization, and where they live. A line is left out
 * when the person did not share any of its fields.
 * @param {object|undefined} me - The person, from `world.me`.
 * @returns {string[]} The lines, in order.
 */
function linesOf(me) {
	const fullName = [me?.title, me?.name, me?.surname].filter(Boolean).join(' ');
	const place = [me?.city, me?.country].filter(Boolean).join(', ');
	return [fullName, me?.organization, place].filter(Boolean);
}

/**
 * Draws who the person is into `container`, then again at every change: their
 * nickname and the profile fields they chose to share with your view when
 * they accepted it in the webapp. Your view gets nothing else about them.
 * @param {HTMLElement} container - Where to draw it.
 * @param {object} world - The world, from connectToHost.
 * @returns {() => void} Stops following the world and removes what it drew.
 */
export function whoAmI(container, world) {
	const box = document.createElement('section');
	box.setAttribute('aria-label', 'Who you are');
	Object.assign(box.style, { display: 'grid', gap: '4px', padding: '16px', borderRadius: '14px', border: '1px solid rgba(127, 127, 127, 0.3)' });
	const nickname = document.createElement('strong');
	nickname.style.fontSize = '18px';
	const details = document.createElement('div');
	Object.assign(details.style, { display: 'grid', gap: '2px' });
	const note = document.createElement('small');
	note.style.opacity = '0.75';
	box.append(nickname, details, note);
	container.append(box);

	// Called at once, then after every change of the world.
	const stop = world.subscribe((node) => {
		// `me` holds the nickname, always, and only the fields the person ticked.
		// It is missing with a webapp older than this kit.
		const me = node.me;
		const lines = linesOf(me);
		nickname.textContent = me?.nickname ?? 'Guest';
		details.replaceChildren(...lines.map((text) => {
			const line = document.createElement('span');
			line.textContent = text;
			return line;
		}));
		if (!me) note.textContent = 'This webapp does not say who you are.';
		else note.textContent = lines.length > 0 ? 'What you chose to share with this view.' : 'You shared only your nickname with this view.';
	});

	return () => {
		stop();
		box.remove();
	};
}

// Using it, on a fake world.

// A fake world to build with. Its `me` is the person as the webapp would give them, with the fields they ticked.
const rowing = {
	name: 'Rowing club',
	me: { nickname: 'ada', name: 'Ada', surname: 'Rossi', organization: 'Siena Rowing Club', city: 'Siena', country: 'Italy' },
};

// While building: the fake world. In the webapp: const world = await connectToHost();
const world = await connectToHost({ fake: { world: rowing } });

const page = document.createElement('div');
Object.assign(page.style, { display: 'grid', gap: '12px', maxWidth: '420px' });
const title = document.createElement('h2');
title.style.margin = '0';
title.textContent = world.name;
const place = document.createElement('div');
page.append(title, place);
document.body.append(page);

whoAmI(place, world);
Live, on a fake world
Open

The component reads world.me (Who the person is) and finds there only the nickname and the fields ticked by the person. It renders up to three lines: (1) title, name and surname, (2) the organization and (3) city and country. A line whose fields are all missing is left out. Under the lines a note reads "What you chose to share with this view." when at least one line is shown and "You shared only your nickname with this view." when none is. A webapp from before 6 November 2026 gives no me and the component then shows Guest with the note "This webapp does not say who you are.".

Because me carries no signature, use it to greet the person and to fill the page and never to grant anything of value on your server (Know who the person is).

Props ​

PropDefaultWhat it is
world(required)The world, from useWorld.

Parameters ​

whoAmI(container, world) draws the box into container and redraws it at every change of the world.

ParameterWhat it is
containerThe element to draw into.
worldThe world, from connectToHost.

It returns a function that unsubscribes from the world and removes the box.

Change it ​

  • Only the nickname: drop the lines of linesOf and render me.nickname alone in a small corner of the screen.
  • Another order: change linesOf to put the organization first in a world about work.
  • The language of the person: the notes are in English. Pick your texts by world.webapp.language.
  • A picture: me holds no picture of the person. Draw their initials from the nickname like Avatar does for the members of a world.

See also ​

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.