'use strict';
import { tryGetFromCoreCache, setCoreCache } from '../../../../fd-toolbox/server/cachings/core-cache.js';
import { fdServerCacheKeys } from '../../../../fd-toolbox/server/constants/fd-server-cache-keys.js';
import { fdRedirect } from '../../../../fd-toolbox/server/framework/index.js';
import { apiUnauthorizedError } from '../../../../fd-toolbox/server/web/errors.js';
import { getSessionToken } from './session-access.js';
import { validateSessionToken } from './session.js';
import { isEmptyNullOrUndefined } from '../../../../fd-toolbox/functions/value-checking-functions.js';
import { getRelativeLoginUrl } from '../../../../fd-toolbox/routing/login-routers.js';

var __defProp=Object['defineProperty'],__name=(_0x2848f3,_0x2aa371)=>__defProp(_0x2848f3,'name',{'value':_0x2aa371,'configurable':!![]});async function apiAuthorize(){const _0x4a877a=await getSessionToken();if(isEmptyNullOrUndefined(_0x4a877a))throw apiUnauthorizedError();const _0x19606f=await validateSessionToken(_0x4a877a);if(isEmptyNullOrUndefined(_0x19606f['userId']))throw apiUnauthorizedError();return _0x19606f;}__name(apiAuthorize,'apiAuthorize');async function requirePageAuth(){const _0x1d1ad7=await pageAuthorize();!_0x1d1ad7&&fdRedirect(getRelativeLoginUrl());}__name(requirePageAuth,'requirePageAuth');async function pageAuthorize(){const _0x1209a9=await getSessionToken();if(!_0x1209a9)return ![];const _0x3413c4=await tryGetFromCoreCache(fdServerCacheKeys['pageAuth'],_0x1209a9);if(_0x3413c4)return _0x3413c4;const _0x5aa383=await validateSessionToken(_0x1209a9),_0x52ea94=!!_0x5aa383['userId'];return await setCoreCache(fdServerCacheKeys['pageAuth'],_0x52ea94,{'slidingExpirationSeconds':fdServerCacheKeys['secondsInFifteenMinutes']},_0x1209a9),_0x52ea94;}__name(pageAuthorize,'pageAuthorize');

export { apiAuthorize, requirePageAuth };
