Who the person is
Your view never signs anyone in because the person is already signed in to UNaIVERSE through the webapp. world.me tells your view who the person is within the limits of what they chose to share with it. me is enough to greet the person or to write their name next to a score. It does not, however, prove to your own server who they are.
me
The first time a person opens a world or an agent with your view, the webapp asks them to accept it and lists what your view will receive about them (Going live). The nickname is always on that list. Each of the other public fields of the profile (name and surname, title, organization, city and country) has a checkbox that starts unticked. The person ticks the fields they want to share.
Your view then gets me, an object that holds the nickname and the ticked fields present in the profile of the person. Like name or messages, me is a field of the world that you read as world.me or as node.me in subscribe.
import { useWorld } from './useWorld.js';
// A fake world to build with: no account, no network.
// `me` is the person who looks at your view, as they chose to share themselves.
const club = {
name: 'Book club',
me: { nickname: 'ada', organization: 'Siena Readers', city: 'Siena' },
};
// The fields a person may share besides the nickname, with the words to show for them.
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>;
// Each field other than the nickname is there only when the person ticked it and their profile has it.
const shared = Object.entries(FIELDS).filter(([field]) => world.me?.[field]);
return (
<>
{/* The nickname is always there. `me` is missing only with a webapp older than the kit. */}
<h2>Welcome, {world.me?.nickname ?? 'guest'}</h2>
<p>You shared with this view:</p>
<ul>
{shared.map(([field, label]) => <li key={field}>{label}: {world.me[field]}</li>)}
{shared.length === 0 && <li>Only your nickname.</li>}
</ul>
</>
);
}import { connectToHost } from '@unaiverse/gui-kit';
// A fake world to build with: no account, no network.
// `me` is the person who looks at your view, as they chose to share themselves.
const club = {
name: 'Book club',
me: { nickname: 'ada', organization: 'Siena Readers', city: 'Siena' },
};
// The fields a person may share besides the nickname, with the words to show for them.
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 intro = document.createElement('p');
intro.textContent = 'You shared with this view:';
const list = document.createElement('ul');
document.body.append(greeting, intro, list);
// Called at once, then after every change of the world.
world.subscribe((node) => {
// The nickname is always there. `me` is missing only with a webapp older than the kit.
greeting.textContent = `Welcome, ${node.me?.nickname ?? 'guest'}`;
// Each other field is there only when the person ticked it and their profile has it.
const items = [];
for (const [field, label] of Object.entries(FIELDS)) {
if (!node.me?.[field]) continue;
const item = document.createElement('li');
item.textContent = `${label}: ${node.me[field]}`;
items.push(item);
}
if (items.length === 0) {
const item = document.createElement('li');
item.textContent = 'Only your nickname.';
items.push(item);
}
list.replaceChildren(...items);
});Your view never gets the email of the person, their exact position, their other worlds and agents or any credential. The webapp does not offer them in the list and the kit drops every field outside it. Read every field except the nickname as optional with ?. and a fallback of your own. A webapp older than the kit gives no me at all. world.me?.nickname ?? 'guest' covers that case too.
On a fake world
A fake world describes the person in me next to its name and its data:
const world = await connectToHost({
fake: { world: { name: 'Book club', me: { nickname: 'ada', city: 'Siena' } } },
});In me write the fields you want to try (the nickname alone or with some of the other fields). A fake world drops every field that the webapp could not give and uses the nickname 'you' when you write none. A fake agent takes me in the same way (fake: { agent: { name, me } }).
identity()
await world.identity() resolves immediately with the same me and asks the person nothing:
const { nickname } = await world.identity();A new view reads world.me. The call remains for views written for an earlier kit in which identity() asked the person and returned a token signed by UNaIVERSE. It rejects with the code 'unavailable' when the webapp gives no me and with 'not-allowed-verb' when the webapp does not know the call.
Your server
me carries no signature. Your view can send it to your server to greet the person, to write their name next to a score or to fill a form for them. Since anyone can call your server with any nickname, the server cannot tell a request of your view from a request with a nickname typed by hand.
When your server must know for certain who the person is (a balance, a purchase, a booking), ask the person to sign in on your own site in a window opened by your view (Popups: logins and payments) and keep a session of your own for them. Your view is a page of your site embedded in another site and many browsers block the cookies of such pages. Keep the session token in the memory of your view and send it in a header.
What the nickname is and is not
- It is public. Anyone in UNaIVERSE can see a nickname. The other fields of
meare public fields of the profile too. - It can change and a freed nickname can go to someone else. Never use it alone as the key of data that you keep for a long time such as a balance or a history of purchases. Link it once to an account of yours through a sign-in on your site and keep your own id.
- Together with the ticked fields it is all you get. For anything more like a delivery address ask the person in your view and explain why you need it.
- It is shared with your view alone. The person shared it with your view in this world or with this agent. Neither pass it on nor use it to track the person elsewhere. Your view and the data it gets are your responsibility (Going live).
Next steps
- Going live: the consent where the person chooses what to share and your responsibility for the data your view gets.
- People and roles: the other members of the world.
- Reference:
world.me,GuiMe,identity. - Recipe: Know who the person is.