Deleted accounts
When a user deletes their Novren ID, or removes only your app from their account, you must delete their data. watchAccountEvents tells your server when.
Watch the events
import { watchAccountEvents } from '@novren/id-verifier'
const events = watchAccountEvents({
idServerUrl: 'https://id.novren.net',
serviceToken: process.env.NOVREN_ID_SERVICE_TOKEN!,
// The whole Novren ID is gone. MUST be idempotent: the same event comes back
// after every restart and every full re-read.
onAccountDeleted: async (accountId) => {
await db.deleteEverythingOf(accountId)
},
// The user removed only your app and kept their Novren ID. Delete only what was
// created BEFORE `before`: they may have started again with the same account since.
onServiceLeft: async (accountId, before) => {
await db.deleteEverythingOf(accountId, { createdBefore: before })
},
onError: (error) => log.warn('Novren ID account events', error.message),
})
events.start()| Option | Required | Default | Meaning |
|---|---|---|---|
idServerUrl | yes | https://id.novren.net. | |
serviceToken | yes | Your service token: you receive only events about your users. | |
onAccountDeleted | yes | The Novren ID was deleted. Delete everything of that account. Must be idempotent. | |
onServiceLeft | no | The user removed only your app. Delete what was created before before. | |
pollMs | no | 60000 | How often new events are read. |
fullResyncMs | no | 6 hours | How often the whole window is re-read from the start. |
onError | no | console.error | Called when a read or a handler fails. |
The two events
account-deleted
The user asked to delete their Novren ID. There is a 30-day grace period: during it the account receives no tokens and can only cancel. The event arrives when the deletion actually happens, at the end of the 30 days.
service-left
The user removed only your app ("Delete a service") and kept their Novren ID. Same grace period. The event carries a date, before: delete only data created before it, because the same user can authorize your app again after the event and start from zero with the same account id.
Why idempotent
The watcher keeps its position in memory and starts from zero at every start, re-reading the whole window (90 days). This way no event is lost if your server was down, and you don't have to store a cursor. The price: the same event arrives more than once. Deleting something already deleted must succeed.
If a handler fails
The watcher stops at that event and retries it at the next round; events after it wait. Better delayed than skipped. onError receives the error: log it and alert, because a handler that always fails blocks the queue.
Without the SDK
GET /service/events?after=<id> with Authorization: Bearer <service token> returns up to 1000 events with id, kind, accountId and at (Unix seconds). See HTTP API.