Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add credentials management api

thecodrr8cda9b0233b5
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index ddfb1ca5f..c5386f87a 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
import { Flex, Button, Text } from "rebass";
import * as Icon from "../icons";
import Dialog, { showDialog } from "./dialog";
@@ -12,7 +12,21 @@ function LoginDialog(props) {
const [error, setError] = useState();
const isLoggingIn = useStore((store) => store.isLoggingIn);
const login = useStore((store) => store.login);
-
+ useEffect(() => {
+ if (!window.PasswordCredential) return;
+ (async function () {
+ navigator.credentials
+ .get({ mediation: "silent", password: true })
+ .then(async (credential) => {
+ if (credential) {
+ await login({
+ username: credential.id,
+ password: credential.password,
+ });
+ }
+ });
+ })();
+ }, [login]);
return (
<Dialog
isOpen={true}
@@ -59,7 +73,21 @@ function LoginDialog(props) {
setError();
login(data)
- .then(onClose)
+ .then(async () => {
+ // Instantiate PasswordCredential with the form
+ if (window.PasswordCredential) {
+ var c = new window.PasswordCredential({
+ id: data.username,
+ name: data.username,
+ type: "password",
+ password: data.password,
+ });
+ await navigator.credentials.store(c);
+ onClose();
+ } else {
+ onClose();
+ }
+ })
.catch((e) => setError(e.message));
}}
flexDirection="column"
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
index ee853439d..143db3c15 100644
--- a/apps/web/src/components/dialogs/signupdialog.js
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -54,7 +54,21 @@ function SignUpDialog(props) {
setError();
signup(data)
- .then(onClose)
+ .then(async () => {
+ // Instantiate PasswordCredential with the form
+ if (window.PasswordCredential) {
+ var c = new window.PasswordCredential({
+ id: data.username,
+ name: data.username,
+ type: "password",
+ password: data.password,
+ });
+ await navigator.credentials.store(c);
+ onClose();
+ } else {
+ onClose();
+ }
+ })
.catch((e) => setError(e.message));
}}
>
@@ -65,12 +79,14 @@ function SignUpDialog(props) {
type="email"
label="Email"
name="email"
+ autoComplete="email"
/>
<Field
required
id="username"
label="Username"
name="username"
+ autoComplete="username"
sx={{ mt: 1 }}
/>
<Field