var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { Auth } from 'aws-amplify';
import _ from 'lodash';
/**
 * Get the JWT tokem for current user session from AWS Cognito.
 *
 * @returns JWT token string if successful.
 * @return Error if no session or no ID token in session
 */
export const GetJwtToken = () => __awaiter(this, void 0, void 0, function* () {
    console.log('** Cognito: getting session **');
    const session = yield Auth.currentSession();
    console.log('Session: ', session);
    if (_.isNil(session)) {
        return new Error('Could not get session');
    }
    const idToken = session.getIdToken();
    console.log('idToken: ', idToken);
    if (_.isNil(idToken) || _.isNil(idToken.getJwtToken)) {
        return new Error('Could not get ID token');
    }
    return idToken.getJwtToken();
});
export default GetJwtToken;
//# sourceMappingURL=GetJwtToken.js.map