@dynamic-labs/sdk-react-core
Version:
A React SDK for implementing wallet web3 authentication and authorization to your website.
74 lines (71 loc) • 3.21 kB
JavaScript
'use client'
import { __awaiter } from '../../../../../_virtual/_tslib.js';
import { createEmailVerification, retryEmailVerification, signInWithEmailVerification } from '../../../data/api/email/email.js';
import '@dynamic-labs/sdk-api-core';
import '@dynamic-labs/utils';
import { storeAuthTokenAndUser } from '../../../store/state/user/storeAuthTokenAndUser/storeAuthTokenAndUser.js';
import '../../../store/state/user/user.js';
import '../../../config/ApiEndpoint.js';
import '../../../store/state/projectSettings/projectSettings.js';
import '../../../utils/constants/values.js';
import '@dynamic-labs/multi-wallet';
import '../../../shared/logger.js';
import '../../../utils/constants/colors.js';
import 'react-international-phone';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import 'react';
import 'react/jsx-runtime';
import '../../ViewContext/ViewContext.js';
import '@dynamic-labs/wallet-book';
import '../../../shared/consts/index.js';
import '../../../store/state/nonce/nonce.js';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../../locale/locale.js';
const createEmailHandler = (environmentId, { shouldRegisterSessionKeysOnSignin, generateSessionKey, }) => (email, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
const createEmailVerificationResponse = yield createEmailVerification({
captchaToken,
email,
environmentId,
});
let { verificationUUID } = createEmailVerificationResponse;
return {
retry: () => __awaiter(void 0, void 0, void 0, function* () {
const retryEmailVerificationResponse = yield retryEmailVerification({
email,
environmentId,
verificationUUID,
});
// eslint-disable-next-line prefer-destructuring
verificationUUID = retryEmailVerificationResponse.verificationUUID;
}),
type: 'email',
verify: (oneTimePassword, options) => __awaiter(void 0, void 0, void 0, function* () {
let sessionPublicKey = undefined;
if (shouldRegisterSessionKeysOnSignin()) {
const keypair = yield generateSessionKey();
sessionPublicKey = keypair.publicKey;
}
const response = yield signInWithEmailVerification({
captchaToken,
environmentId,
sessionPublicKey,
verificationToken: oneTimePassword,
verificationUUID,
});
// Skip setting the user auth token and only return the VerifyResponse
// if needed because setUser can trigger view re-renders.
if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
storeAuthTokenAndUser(response);
}
return {
destination: email,
response: response,
verified: true,
};
}),
};
});
export { createEmailHandler };