--- title: IdentityManager.watch() slug: Web/API/IdentityManager/watch translation_of: Archive/IdentityManager/watch ---
{{ ApiRef("Persona") }}
This function registers callbacks that respond to a Persona user logging in or out.
navigator.id.watch({ loggedInUser: 'bob@example.org', onlogin: function(assertion) { // A user has logged in! Here you need to: // 1. Send the assertion to your backend for verification and to create a session. // 2. Update your UI. }, onlogout: function() { // A user has logged out! Here you need to: // Tear down the user's session by redirecting the user or making a call to your backend. } });
loggedInUser
{{ optional_inline() }}loggedInEmail
in early September. Both names will continue to work for the time being, but code should be changed to use loggedInUser
instead.null
otherwise. If the website is unsure, this should be set to undefined
or omitted.loggedInUser
to determine which callback—onlogin
, onlogout
, or none at all—to automatically invoke when your page loads. If loggedInUser
is undefined
or omitted, Persona will invoke either onlogin
or onlogout
, depending on whether or not a local user should be logged in to your site. These callbacks are not invoked automatically if both BrowserID and loggedInUser
agree on the local user's state.onlogin
or onlogout
when your page loads, but not both. If loggedInUser
is set to foo@example.com
, but Persona believes bar@example.com
should be logged in, only onlogin
will be called. It will have an assertion for bar@example.com
as its first parameter.onlogin
onlogout
需要示例.
没有包含在任何技术规范中.