list-sessions.js 727 B

1234567891011121314151617181920212223
  1. const eggspress = require("../../api/eggspress");
  2. const { UserActorType } = require("../../services/auth/Actor");
  3. const { Context } = require("../../util/context");
  4. module.exports = eggspress('/auth/list-sessions', {
  5. subdomain: 'api',
  6. auth2: true,
  7. allowedMethods: ['GET'],
  8. }, async (req, res, next) => {
  9. const x = Context.get();
  10. const svc_auth = x.get('services').get('auth');
  11. // Only users can list their own sessions
  12. // apps, access tokens, etc should NEVER access this
  13. const actor = x.get('actor');
  14. if ( ! (actor.type instanceof UserActorType) ) {
  15. throw APIError.create('forbidden');
  16. }
  17. const sessions = await svc_auth.list_sessions(actor);
  18. res.json(sessions);
  19. });