A simple site to track my kid's computer time, tasks & rewards with bitcoin
- LNbits (I recommend running your own instance)
- Atlas Realm MongoDB account
- Enable Email Authentication
- Use your own Realm App ID
- Use the demo site or host it yourself
LNbits has to be running via https or tor ✔️
- Create a wallet specific for the reward withdrawals
- Copy the Admin key from the wallet. Wallet > API docs > Admin key
- Save the Admin key in a
lnbits_wallet_admin_key
property of your user'suser_data
(UI coming soon) - Install the LNURLw extension and active it for your user
Atlas > Data Services > Database > [Create]; name it mongodb-atlas.
If you want to change the name, change the value for CLUSTER_NAME
in app.js
.
Below is my configuration:
* Shared
* Cloud Provider:
* Region: Oregon (us-west-2)
* Cluster Tier: M0 Sandbox (Shared RAM, 512 MB Storage)
* MongoDB 6.0
Atlas > Data Services > Database > Cluster0 > Collection > [Create Database]; name it computer-time.
If you want to change the name, change the value for DATABASE_NAME
in app.js
.
Atlas > App Services > [Create a New App]
Atlas > App Services > App > Schema > Collections > Add a collection. Make sure you create the collections within the computer-time database and create the below schemas:
log
{
"title": "log",
"properties": {
"_id": {
"bsonType": "objectId"
},
"timestamp": {
"bsonType": "date"
},
"type": {
"bsonType": "string"
},
"userAgent": {
"bsonType": "string"
},
"owner_id": {
"bsonType": "string"
}
}
}
tasks
{
"properties": {
"_id": {
"bsonType": "objectId"
},
"timestamp": {
"bsonType": "date"
},
"description": {
"bsonType": "string"
},
"sats": {
"bsonType": "int"
},
"qrcode": {
"bsonType": "string"
},
"status": {
"bsonType": "string"
},
"owner_id": {
"bsonType": "string"
}
},
"required": [
"_id",
"timestamp",
"description",
"sats",
"qrcode",
"status"
]
}
Make sure you name the first one log and the other one tasks. otherwise update you app.js.
Atlas > App Services > App > Rules > Collections > mongodb-atlas > computer-time
Rules allow set appropriate permissions for reading, writing on data, I have the following rules to each of the collections created above
log
{
"roles": [
{
"name": "admin",
"apply_when": {
"%%user.custom_data.isGlobalAdmin": true
},
"document_filters": {
"write": true,
"read": true
},
"read": true,
"write": true,
"insert": true,
"delete": true,
"search": true
},
{
"name": "user",
"apply_when": {},
"document_filters": {
"write": {
"owner_id": "%%user.id"
},
"read": {
"owner_id": "%%user.id"
}
},
"read": true,
"write": true,
"insert": true,
"delete": false,
"search": true
}
]
}
tasks
{
"roles": [
{
"name": "Admin",
"apply_when": {
"%%user.custom_data.isGlobalAdmin": true
},
"document_filters": {
"write": true,
"read": true
},
"read": true,
"write": true,
"insert": true,
"delete": true,
"search": true
},
{
"name": "readAllWriteOwn",
"apply_when": {},
"document_filters": {
"write": {
"owner_id": {
"$in": [
null,
"%%user.id"
]
}
},
"read": true
},
"read": true,
"write": true,
"insert": true,
"delete": false,
"search": true
}
]
}
Atlas > App Services > App > App Users > Authentication Providers; Only enable Email/Password.
Atlas > App Services > App > App Users > UserAPI Settings > Enable Custom UserAPI Data; use the following configuration:
Cluster Name: mongodb-atlas
Database Name: computer-time
Collection Name: user_data
UserAPI ID Field: owener_id
I use the Custom UserAPI Data to store username
and to set admin privileges using the isGlobalAdmin
property
6. Enable Device Sync
Atlas > App Services > App > Device Sync
- Flexible
- Development Mode: Off
- Queryable Fields: _id, owner_id
No compiling necessary, just launch the demo site and enter your App Id, email and password, and you should be all set.
- Use the
appId
URL param to send your Realm App ID, i.e.:index.html?appId=<blah-blah-blah>
- Use the
lnbitsHost
URL param to send the LNbits hostname, i.e.:index.html?appId=<blah>&lnbitsHost=https%3A%2F%2Fraspberrypi.local
- Atlas, MongoDB and Realm are not free, but they do offer free tiers.
- This is an experiment, don't use it for production applications. DYOR.
- A lot of the logic should exist in a proper backend environment.
- License: GNU GENERAL PUBLIC LICENSE
Project developed with ♥ from AZ with HTML, JS and Mongo Realm Web SDK