auth

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

settings.js (1132B)


      1 import { app } from '../../app.js';
      2 import { authenticateAdminRequest } from '../../lib/admin-auth.js';
      3 import {
      4   getAdminRealmSettings,
      5   updateAdminRealmSettings,
      6 } from '../../lib/admin-settings.js';
      7 
      8 export default [
      9   {
     10     method: 'get',
     11     path: '/api/v1/admin/realms/:realm/settings',
     12     name: 'admin.settings.get',
     13     async handler(req) {
     14       const auth = await authenticateAdminRequest(req, {
     15         realmSlug: req.params.realm,
     16       });
     17       const settings = await getAdminRealmSettings(auth.realmDb, auth.realm.slug);
     18 
     19       return new app.HttpOk({ settings }, { 'cache-control': 'no-store' });
     20     },
     21   },
     22   {
     23     method: 'patch',
     24     path: '/api/v1/admin/realms/:realm/settings',
     25     name: 'admin.settings.update',
     26     async handler(req) {
     27       const auth = await authenticateAdminRequest(req, {
     28         realmSlug: req.params.realm,
     29       });
     30       const settings = await updateAdminRealmSettings({
     31         realmDb: auth.realmDb,
     32         realmSlug: auth.realm.slug,
     33         body: req.body || {},
     34       });
     35 
     36       return new app.HttpOk({ ok: true, settings }, { 'cache-control': 'no-store' });
     37     },
     38   },
     39 ];