auth

Main authentication module for my projects
git clone git://git.finwo.net/app/auth
Log | Files | Refs

delete.js (856B)


      1 import { app } from '../../../app.js';
      2 import { authenticateAdminSession } from '../../../lib/admin-auth.js';
      3 import { deleteAdminRealm } from '../../../lib/admin-realms.js';
      4 import { HttpError } from '../../../lib/http/http-error.js';
      5 import { findRealmBySlug } from '../../../lib/realm.js';
      6 
      7 export default {
      8   method: 'delete',
      9   path: '/api/v1/admin/realms/:realm',
     10   name: 'admin.realms.delete',
     11   async handler(req) {
     12     const auth = await authenticateAdminSession(req);
     13     const realm = await findRealmBySlug(req.params.realm);
     14     if (!realm) {
     15       throw new HttpError(404, 'unknown_realm', 'Unknown realm');
     16     }
     17 
     18     const result = await deleteAdminRealm({
     19       systemDb: auth.systemDb,
     20       actor: auth.user,
     21       realm,
     22     });
     23 
     24     return new app.HttpOk({ ok: true, removed: result.removed }, { 'cache-control': 'no-store' });
     25   },
     26 };