auth

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

delete.js (1046B)


      1 import { app } from '../../../app.js';
      2 import { authenticateAdminRequest } from '../../../lib/admin-auth.js';
      3 import { assertAdminRealmUser } from '../../../lib/admin-users.js';
      4 import { deleteBan } from '../../../lib/bans.js';
      5 import { HttpError } from '../../../lib/http/http-error.js';
      6 
      7 export default {
      8   method: 'delete',
      9   path: '/api/v1/admin/realms/:realm/users/:userId/bans/:clientId',
     10   name: 'admin.bans.delete',
     11   async handler(req) {
     12     const auth = await authenticateAdminRequest(req, {
     13       realmSlug: req.params.realm,
     14     });
     15     const user = await assertAdminRealmUser({
     16       systemDb: auth.systemDb,
     17       realmDb: auth.realmDb,
     18       realm: auth.realm,
     19       userId: req.params.userId,
     20     });
     21 
     22     const removed = await deleteBan(auth.realmDb, {
     23       userId: user.id,
     24       clientId: req.params.clientId,
     25     });
     26     if (!removed) {
     27       throw new HttpError(404, 'ban_not_found', 'Ban not found');
     28     }
     29 
     30     return new app.HttpOk(
     31       { ok: true, removed: true },
     32       { 'cache-control': 'no-store' }
     33     );
     34   },
     35 };