CredentialsContainer: store() Methode
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Januar 2020.
Sicherer Kontext: Diese Funktion ist nur in sicheren Kontexten (HTTPS) in einigen oder allen unterstützenden Browsern verfügbar.
Die store()-Methode des CredentialsContainer speichert ein Set von Anmeldeinformationen für den Benutzer in einer Credential-Instanz und gibt diese in einem Promise zurück.
Hinweis:
Diese Methode ist auf oberste Kontexte beschränkt. Aufrufe innerhalb eines <iframe>-Elements werden ohne Wirkung aufgelöst.
Syntax
store(credentials)
Parameter
credentials-
Eine gültige
Credential-Instanz.
Rückgabewert
Ein Promise, das auf undefined aufgelöst wird.
Ausnahmen
NotAllowedErrorDOMException-
Wird ausgelöst, wenn es bereits eine Anmeldeinformation des gleichen Typs wie die aktuelle gibt, die in Bearbeitung ist.
Beispiele
>Speichern einer Passwort-Anmeldeinformation bei erfolgreicher Authentifizierung
Dieses Codebeispiel wird ausgeführt, nachdem sich ein Benutzer angemeldet oder registriert hat und der Server die Anmeldeinformation als korrekt bestätigt hat.
// Check if the browser supports password credentials (and the Credential Management API)
if ("PasswordCredential" in window) {
let credential = new PasswordCredential({
id: "example-username",
name: "Carina Anand", // In case of a login, the name comes from the server.
password: "correct horse battery staple",
});
navigator.credentials.store(credential).then(
() => {
console.info("Credential stored in the user agent's credential manager.");
},
(err) => {
console.error("Error while storing the credential: ", err);
},
);
}
Spezifikationen
| Specification |
|---|
| Credential Management Level 1> # dom-credentialscontainer-store> |
Browser-Kompatibilität
Loading…