UNPKG

trainingpeaks-sdk

Version:
25 lines (24 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAthleteIdFromSession = void 0; const http_errors_1 = require("../../adapters/errors/http-errors.js"); const error_codes_1 = require("../../domain/errors/error-codes.js"); const getAthleteIdFromSession = async (deps) => { deps.logger.info('No athleteId provided, getting from current user session'); const session = await deps.sessionStorage.get(); if (!session) { const httpErrorResponse = { status: 401, statusText: 'Unauthorized', data: { message: error_codes_1.ERROR_MESSAGES[error_codes_1.ERROR_CODES.AUTH_NO_ACTIVE_SESSION] }, }; throw (0, http_errors_1.createHttpError)(httpErrorResponse, { url: 'session', method: 'GET', }); } const athleteId = session.user.id; deps.logger.info('Using current user ID as athleteId', { athleteId }); return athleteId; }; exports.getAthleteIdFromSession = getAthleteIdFromSession;