MongoDB CRUD & Auth Backend
as your template. Then click Create App.generate_keys
- This is a task that can be used to generate a private/public key pair which the jwks
and token
tasks (see below) require.generate_keys
task does not expose an HTTP endpoint and should only be used for development and getting started.jwks
- This task exposes an HTTP endpoint which has a GET
function which returns the public JWKS details.token
- This task exposes an HTTP endpoint which has a GET
function. The task is used by a PowerSync client to generate a token to validate against the PowerSync Service.
For more information about custom authentication setups for PowerSync, please see here.upload
- This task exposes an HTTP endpoint which has a POST
function which is used to process the write events from a PowerSync client and writes it back to the source MongoDB database.generate_keys
CloudCode task.POWERSYNC_PUBLIC_KEY
and POWERSYNC_PRIVATE_KEY
to a file — we’ll need this in the next step.Testing
deployment. You can configure different deployments for different environments (e.g. staging, production)<domain_name>.poweredbyjourney.com
. Open the browser and navigate to the new domain. You should be presented with Cannot GET /
, because there is no index route.POWERSYNC_PUBLIC_KEY
- This is the POWERSYNC_PUBLIC_KEY
from the values generated in step 1.POWERSYNC_PRIVATE_KEY
- This is the POWERSYNC_PRIVATE_KEY
from the values generated in step 1.MONGO_URI
- This is the MongoDB URI e.g. mongodb+srv://<username>:<password>@<database_domain>/<database>
POWERSYNC_URL
- This is the public PowerSync URL that is provided after creating a new PowerSync instance.<domain_name>.poweredbyjourney.com/jwks
.
If the setup was successful, the jwks
task will render the keys in JSON format. Make sure the format of your JWKS keys matches the format in this example JWKS endpoint.
token
HTTP API endpoint when you implement the fetchCredentials()
function on the client application.
Send an HTTP GET request to <domain_name>.poweredbyjourney.com/token?user_id=<user_id>
to fetch a JWT for a user. You must provide a user_id
in the query string of the request, as this is included in the JWT that is generated.
The response of the request would look like this:
jwks
HTTP API endpoint is used by PowerSync to validate the token returned from the <domain_name>.poweredbyjourney.com/token
endpoint. This URL must be set in the configuration of your PowerSync instance.
Send an HTTP GET request to <domain_name>.poweredbyjourney.com/jwks
.
An example of the response format can be found using this link.
upload
HTTP API endpoint when you implement the uploadData()
function on the client application.
Send an HTTP POST request to <domain_name>.poweredbyjourney.com/upload
.
The body of the request payload should look like this:
batch
should be an array of operations from the PowerSync client SDK.op
refers to the type of each operation recorded by the PowerSync client SDK (PUT
, PATCH
or DELETE
). Refer to Writing Client Changes for details.table
refers to the table in SQLite where the operation originates from, and should match the name of a collection in MongoDB.200
if the write was successful.
upload
task writes data to the source MongoDB database.
Here is how:
upload
task in the panel on the left.index.ts
contains the entry point function that accepts the HTTP request and has a MongoDBStorage
class which interacts with the MongoDB database to perform inserts, updates and deletes. To adjust how updates are performed, take a look at the updateBatch
function.