UNPKG

trainingpeaks-sdk

Version:
21 lines (20 loc) 824 B
import { createHttpError } from '../../adapters/errors/http-errors.js'; import { ERROR_CODES, ERROR_MESSAGES } from '../../domain/errors/error-codes.js'; export 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_MESSAGES[ERROR_CODES.AUTH_NO_ACTIVE_SESSION] }, }; throw createHttpError(httpErrorResponse, { url: 'session', method: 'GET', }); } const athleteId = session.user.id; deps.logger.info('Using current user ID as athleteId', { athleteId }); return athleteId; };