For more words, see the blog post too
We need a few modules. This uses several Bicycle Computing libraries, and the keystore from Fission.
- @bicycle-codes/identity -- identity
- @oddjs/odd -- save a non-extractable keypair in indexedDB
- @bicycle-codes/request -- verify HTTP requests via headers
I am using a database with Fauna DB, and a websocket via Patykit also.
See code in the example folder.
The app flow is designed like this:
-
You open the app for the first time. The app prompts you to create a new identity. You create an identity. At this point you can save data, and it will be encrypted and backed up on the server.
-
You visit the app from a second device, like your phone. At the bottom of the app are links -- "Link a device to this account" and "Add this device to an existing account".
-
Use the app to add a second device to your account. This uses the identity module + a websocket via Partykit to facilitate multiple devices reading the same data.
Note that this is not a demonstration of CRDTs or any kind of state reconciliation. The push
and pull
buttons will simply overwrite the remote or local state.
This can work alright if you are only dealing with updates from a single user. We can assume that a single user would be mindful about which device is most up to date, and would push and pull accordingly.
Serverside, we handle auth using HTTP headers, via the request module.
Start a local server with vite
, a local partykit websocket server, and serve the lambda functions locally. (A complete environment can run locally.)
npm start
You need to add an environment variable for the database. In the root directory, create a file .env
:
FAUNA_SECRET="abc123"