UNPKG

@furystack/websocket-api

Version:
42 lines 1.86 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Injectable, Injected } from '@furystack/inject'; import { HttpUserContext } from '@furystack/rest-service'; /** * Example action that returns the current user instance */ let WhoAmI = class WhoAmI { [Symbol.dispose]() { /** */ } static canExecute(options) { // eslint-disable-next-line @typescript-eslint/no-base-to-string const stringifiedValue = options.data.toString(); return stringifiedValue === 'whoami' || stringifiedValue === 'whoami /claims'; } async execute(options) { try { const currentUser = await this.httpUserContext.getCurrentUser(options.request); options.socket.send(JSON.stringify({ currentUser })); } catch (error) { options.socket.send(JSON.stringify({ currentUser: null })); } } }; __decorate([ Injected(HttpUserContext), __metadata("design:type", HttpUserContext) ], WhoAmI.prototype, "httpUserContext", void 0); WhoAmI = __decorate([ Injectable({ lifetime: 'transient' }) ], WhoAmI); export { WhoAmI }; //# sourceMappingURL=whoami.js.map