world.identity()
Resolves to the world.me object. It describes the person using your view and holds only the fields that person chose to share with it.
const { nickname } = await world.identity();Parameters
None.
Returns
A Promise that resolves to a GuiMe. It always holds the nickname of the person. Among the public fields of their profile (name, surname, title, organization, city, country) it holds only those ticked by the person when they accepted your view. The Promise resolves at once without asking the person anything and the object carries no signature.
Usage
Read the person in a view written for the earlier kit
In an earlier version of the kit identity() asked the person for consent and resolved to a token signed by UNaIVERSE. A view written for that kit keeps working and now receives me in place of the token:
const person = await world.identity();
greeting.textContent = `Welcome, ${person.nickname}`;A new view reads world.me instead. It is already present when connectToHost resolves and needs no await:
greeting.textContent = `Welcome, ${world.me?.nickname ?? 'guest'}`;Send the nickname to your server
A score kept by your server can carry the nickname of the person who made it:
async function saveScore(score) {
const { nickname } = await world.identity();
await fetch('https://api.your.site/scores', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ nickname, score }),
});
}Your server receives a nickname that anyone could have written. Use it to show a name. When your server must be sure of who the person is, ask them to sign in on your own site (Who the person is).
Caveats
- No signature. Your server cannot tell the nickname your view sends from one written by hand. Never treat it as proof of who the person is.
- A nickname can change and someone else can later take a nickname that was given up. Do not use it as the only key of data you keep about a person for a long time.
- Only what the person ticked. A field other than the nickname is missing when the person did not tick it or when their profile lacks it.
- With a fake world it resolves to the
meof the fake world. A fake world withoutmegives the nickname'you'(Fake worlds).
Troubleshooting
| Code | Why | What to do |
|---|---|---|
'unavailable' | The webapp gives your view no me. | Continue without knowing who the person is. |
'not-allowed-verb' | This webapp is older than your kit and does not know identity. | Continue without knowing who the person is. |
See also
world.meand the typeGuiMe.- Who the person is, the recipe Know who the person is and the component WhoAmI.