Know who the person is
When a person accepts your view in the webapp, they choose what it may know about them. Your view always receives the nickname. It also receives the public fields of the profile that the person ticks (name and surname, title, organization, city and country) when the profile contains them. Your view reads all of it in world.me without asking the person anything or checking a token. The example gives its fake world a me of its own for a person who shared their city and greets that person by nickname.
import { useWorld } from './useWorld.js';
// Building with a fake world needs no account and no network.
// The `me` of the fake world is the person as the webapp would give them, with the nickname and here the city they chose to share.
const club = {
name: 'Book club',
now: { text: 'This month: The Name of the Rose' },
me: { nickname: 'ada', city: 'Siena' },
};
/** The profile fields a person may share with your view, with the words to show for each. */
const FIELDS = { name: 'Name', surname: 'Surname', title: 'Title', organization: 'Organization', city: 'City', country: 'Country' };
export default function App() {
// While building: the fake world. In the webapp: useWorld()
const { world, error } = useWorld({ fake: { world: club } });
if (error) return <p>Could not connect ({error.code}).</p>;
if (!world) return <p>Connecting…</p>;
// `me` holds the nickname, always, and only the fields the person chose to share.
// It is missing with a webapp older than this kit, and the view then greets a guest.
const me = world.me;
const shared = Object.keys(FIELDS).filter((field) => me?.[field]);
return (
<>
<h2>Welcome, {me?.nickname ?? 'guest'}</h2>
<p>{shared.length > 0 ? 'You also shared:' : 'You shared only your nickname.'}</p>
<ul>
{shared.map((field) => <li key={field}>{FIELDS[field]}: {me[field]}</li>)}
</ul>
<p>{world.now?.text}</p>
</>
);
}import { connectToHost } from '@unaiverse/gui-kit';
// Building with a fake world needs no account and no network.
// The `me` of the fake world is the person as the webapp would give them, with the nickname and here the city they chose to share.
const club = {
name: 'Book club',
now: { text: 'This month: The Name of the Rose' },
me: { nickname: 'ada', city: 'Siena' },
};
/** The profile fields a person may share with your view, with the words to show for each. */
const FIELDS = { name: 'Name', surname: 'Surname', title: 'Title', organization: 'Organization', city: 'City', country: 'Country' };
// While building: the fake world. In the webapp: const world = await connectToHost();
const world = await connectToHost({ fake: { world: club } });
const greeting = document.createElement('h2');
const sharedTitle = document.createElement('p');
const sharedList = document.createElement('ul');
const now = document.createElement('p');
document.body.append(greeting, sharedTitle, sharedList, now);
// Called at once, then after every change of the world.
world.subscribe((node) => {
// `me` holds the nickname, always, and only the fields the person chose to share.
// It is missing with a webapp older than this kit, and the view then greets a guest.
const me = node.me;
greeting.textContent = `Welcome, ${me?.nickname ?? 'guest'}`;
const shared = Object.keys(FIELDS).filter((field) => me?.[field]);
sharedTitle.textContent = shared.length > 0 ? 'You also shared:' : 'You shared only your nickname.';
sharedList.replaceChildren(...shared.map((field) => {
const item = document.createElement('li');
item.textContent = `${FIELDS[field]}: ${me[field]}`;
return item;
}));
now.textContent = node.now?.text ?? '';
});How it works
world.meholdsnicknameand only the fields the person ticked. A field they did not tick is missing rather than empty. Insubscribethe same object isnode.me.- Your view never gets the email, the exact position, the agents and worlds of the person or any credential because the consent of the webapp does not offer them.
- A webapp older than this kit gives no
me. Read it asworld.me?.nicknameand have something to show for a guest. await world.identity()resolves at once with the samemeand asks the person nothing. It exists for views written for an earlier kit and rejects with the code'unavailable'when the webapp gives nome.- In a fake world, write
menext to thenameof the world. Without it the person has the nickname'you'and nothing else.
On your server
me carries no signature and whoever has the page open can change it like anything else the webapp gave the page. A nickname that your view sends to your server is good for greeting the person or for remembering a harmless choice and never for granting something of value. Your server shows how to verify who the person is with a sign-in on your own site. A nickname alone is a poor key for what your server stores because it can change and a freed nickname can go to someone else (The nickname).
See also
- Who the person is: the full topic and what your server can do with it.
identityGuiMe: every field ofme.WhoAmI: a ready component that shows who the person is.