Sessions & folders#

These endpoints back the Active Sessions and Chat Folders settings screens. All require authentication. A session is created on POST /api/auth/login and POST /api/auth/register; the s_… token they return is the session. Pass an optional device + platform on login so the session is identifiable in the list.

Active sessions#

POST /api/getSessions#

The caller's signed-in sessions, current first. Takes no body.

curl -X POST http://localhost:4000/api/getSessions \
  -H "authorization: Bearer s_…"
{
  "ok": true,
  "result": {
    "sessions": [
      { "id": "a1b2…", "current": true,  "device": "iPhone 15", "platform": "ios", "app_version": "Mafold iOS 0.1.0", "created_at": "2026-06-24T…", "last_seen": "2026-06-24T…" },
      { "id": "c3d4…", "current": false, "device": "Chrome 141", "platform": "web", "app_version": "Mozilla/5.0…", "created_at": "…", "last_seen": "…" }
    ],
    "auto_terminate_days": 180
  }
}

The id is a non-secret public id (the secret is the s_… token, never returned). current marks the session making the request.

POST /api/terminateSession#

Revoke one of the caller's sessions by id. Body: { "id": "c3d4…" }. Returns { "ok": true }, or a not_found error if no such session.

POST /api/terminateOtherSessions#

Log out every device except the one making the request. Takes no body. Returns { "terminated": 3 }.

POST /api/setAutoTerminate#

Auto-terminate sessions inactive for N days (0 = off). Body: { "days": 180 }. Returns { "days": 180 }.

Chat folders#

A folder is a named, ordered grouping of conversations, scoped to the account.

POST /api/getFolders#

The caller's folders, in order. Takes no body. Returns { "folders": [ { "id", "title", "emoji", "conv_ids": [] } ] }.

POST /api/saveFolder#

Create (blank/absent id) or update (existing id) a folder. Body: { "id?": "…", "title": "Work", "emoji?": "💼", "conv_ids?": ["…"] }. title is required. Returns { "folder": { … } } with the final id.

POST /api/deleteFolder#

Remove a folder by id. Body: { "id": "…" }. Returns { "ok": true|false }.

POST /api/reorderFolders#

Reorder by an id sequence (drag-and-drop). Body: { "ids": ["id2","id1"] }. Ids not listed keep their relative order at the end. Returns the new { "folders": [ … ] }.