'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../../../../_virtual/_tslib.cjs');
var client = require('@dynamic-labs-sdk/client');
var utils$1 = require('@dynamic-labs/utils');
require('@dynamic-labs-sdk/client/core');
require('@dynamic-labs/sdk-api-core');
require('../../../client/client.cjs');
require('react');
require('../../../config/ApiEndpoint.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('react/jsx-runtime');
require('../../../context/ViewContext/ViewContext.cjs');
require('../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('../../../utils/constants/colors.cjs');
require('../../../utils/constants/values.cjs');
require('../../../shared/consts/index.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../store/state/nonce/nonce.cjs');
var api = require('../api.cjs');
var utils = require('../utils.cjs');
require('@dynamic-labs/locale');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../../events/dynamicEvents.cjs');
var storeTokenAndUser = require('../../../client/extension/storeTokenAndUser/storeTokenAndUser.cjs');

/**
 * @deprecated Use `signInWithExternalJwt` instead.
 * This currently does not work.
 */
const externalAuthVerify = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ environmentId, externalJwt, }) {
    try {
        /* istanbul ignore next */
        const response = (yield api.sdkApi().externalAuthVerify({
            environmentId,
            externalAuthSigninRequest: {
                jwt: externalJwt,
            },
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
        }));
        return storeTokenAndUser.storeTokenAndUser(response);
    }
    catch (e) {
        const data = yield utils.logResponseError(e, 'Error verifying external JWT');
        if (data.code === 'invalid_external_auth') {
            throw new client.InvalidExternalAuthError({
                cause: data,
            });
        }
        if (data.error.code === 'sandbox_maximum_threshold_reached') {
            throw new utils$1.SandboxMaximumThresholdReachedError(data.error.message);
        }
        throw new utils$1.DynamicError(data.error);
    }
});

exports.externalAuthVerify = externalAuthVerify;
