So, we are using Moralis and what we did was to override their web3auth connector that uses the openloginadapter code you provided. But we still are not able to get it to work.
`import Moralis from 'moralis';
import { ethers } from 'ethers';
//import verifyChainId from '../utils/verifyChainId';
import { WALLET_ADAPTERS, CHAIN_NAMESPACES } from '@web3auth/base';
import { OpenloginAdapter } from '@web3auth/openlogin-adapter';
export default class Web3AuthConnector extends Moralis.AbstractWeb3Connector {
type = 'web3Auth';
connect = (web3auth) => {
console.log('Using custom Web3AuthConnector');
return new Promise((resolve, reject) => {
const subscribeAuthEvents = (web3auth) => {
web3auth.loginModal.on('MODAL_VISIBILITY', async (visibility) => {
if (!visibility) {
reject(new Error('Web3Auth: User closed login modal.'));
}
});
};
subscribeAuthEvents(web3auth);
web3auth.connect().then(resolve).catch(reject);
});
};
activate = async ({
chainId = NEXT_PUBLIC_WEB3AUTH_CHAINID,
clientId,
theme,
appLogo,
loginMethodsOrder,
} = {}) => {
// Checking that all params are given
if (!clientId) {
throw new Error('"clientId" not provided, please provide clientId');
}
@web3auth/core" not installed, please install’);
}
// Build config
const ethChainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: chainId,
};
// Build Web3Auth
let web3auth;
try {
web3auth = new Web3Auth({
chainConfig: ethChainConfig,
clientId: clientId,
});
const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
network:
NEXT_PUBLIC_TRANSAK_ENVIRONMENT == ‘STAGING’
? ‘testnet’
: ‘mainnet’,
uxMode: ‘popup’,
whiteLabel: {
name: ‘DualMint Marketplace’,
logoLight: ‘/LogoLight.png’,
logoDark: ‘/LogoDark.png’,
defaultLanguage: ‘en’,
dark: true, // whether to enable dark mode. defaultValue: false
},
},
});
web3auth.configureAdapter(openloginAdapter);
} catch {
// Do Nothing error checked below
}
if (!web3auth) {
throw new Error(
‘Could not connect via Web3Auth, error during initializing Web3Auth’
);
}
// Authenticate
await web3auth.initModal({
modalConfig: {
[WALLET_ADAPTERS.OPENLOGIN]: {
label: "openlogin",
// setting it to false will hide all social login methods from modal.
showOnModal: true,
},
},
});
let provider = null;
provider = await this.connect(web3auth);
if (!provider) {
throw new Error(
‘Could not connect via Web3Auth, error in connecting to provider’
);
}
// Gather User data
try {
const isSocialLogin = web3auth?.provider ? false : true;
const ether = new ethers.providers.Web3Provider(
web3auth?.provider ? web3auth.provider : web3auth
);
const signer = ether.getSigner();
const values = await Promise.all([
ether.getNetwork(),
signer.getAddress(),
]);
const providerChainId = values[0].chainId;
this.account = values[1].toLocaleLowerCase();
this.chainId = 0x${providerChainId.toString(16)}
;
this.provider = isSocialLogin ? ether : web3auth?.provider;
this.web3Instance = web3auth;
this.subscribeToEvents(this.provider);
return {
chainId: this.chainId,
account: this.account,
provider: this.provider,
};
} catch {
throw new Error(
‘Could not connect via Web3Auth, error while authenticating’
);
}">
// Initalizing Web3Auth and getting constants
let Web3Auth;
try {
Web3Auth = require(‘@web3auth/modal’)?.Web3Auth;
} catch {
// Do Nothing Individual Checks are done below
}
// Check if user is using CDN to import
if (!Web3Auth) {
Web3Auth = window?.Web3auth?.Web3Auth;
}
// Error checking for if library is not installed
if (!Web3Auth) {
throw new Error(‘“@web3auth/core” not installed, please install’);
}
// Build config
const ethChainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: chainId,
};
// Build Web3Auth
let web3auth;
try {
web3auth = new Web3Auth({
chainConfig: ethChainConfig,
clientId: clientId,
});
const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
network:
NEXT_PUBLIC_TRANSAK_ENVIRONMENT == ‘STAGING’
? ‘testnet’
: ‘mainnet’,
uxMode: ‘popup’,
whiteLabel: {
name: ‘DualMint Marketplace’,
logoLight: ‘/LogoLight.png’,
logoDark: ‘/LogoDark.png’,
defaultLanguage: ‘en’,
dark: true, // whether to enable dark mode. defaultValue: false
},
},
});
web3auth.configureAdapter(openloginAdapter);
} catch {
// Do Nothing error checked below
}
if (!web3auth) {
throw new Error(
‘Could not connect via Web3Auth, error during initializing Web3Auth’
);
}
// Authenticate
await web3auth.initModal({
modalConfig: {
[WALLET_ADAPTERS.OPENLOGIN]: {
label: “openlogin”,
// setting it to false will hide all social login methods from modal.
showOnModal: true,
},
},
});
let provider = null;
provider = await this.connect(web3auth);
if (!provider) {
throw new Error(
‘Could not connect via Web3Auth, error in connecting to provider’
);
}
// Gather User data
try {
const isSocialLogin = web3auth?.provider ? false : true;
const ether = new ethers.providers.Web3Provider(
web3auth?.provider ? web3auth.provider : web3auth
);
const signer = ether.getSigner();
const values = await Promise.all([
ether.getNetwork(),
signer.getAddress(),
]);
const providerChainId = values[0].chainId;
this.account = values[1].toLocaleLowerCase();
this.chainId = 0x${providerChainId.toString(16)}
;
this.provider = isSocialLogin ? ether : web3auth?.provider;
this.web3Instance = web3auth;
this.subscribeToEvents(this.provider);
return {
chainId: this.chainId,
account: this.account,
provider: this.provider,
};
} catch {
throw new Error(
‘Could not connect via Web3Auth, error while authenticating’
);
}
};
deactivate = async () => {
this.unsubscribeToEvents(this.provider);
if (this.web3Instance) {
await this.web3Instance.logout();
}
this.account = null;
this.chainId = null;
this.provider = null;
};
}
`
Originally posted by:
billtlee