lisa
October 3, 2023, 12:47pm
1
Please provide the following details too when asking for help in this category:
Hello, I am trying to get idToken for Android, but web3Auth return empty idToken. For IOS work correct, but not Android.
const info = web3Auth.userInfo(); const privKey = web3Auth.privKey; const idToken = info?.idToken;
SDK Version: 5.0.0
Expo or Bare Version:
Screenshots of error:
Related to Custom Authentication? Please provide the following info too: (Optional)
Verifier Name:
JWKS Endpoint:
Sample idToken(JWT)
Please provide the Web3Auth initialization and login code snippet below:
vjgee
October 3, 2023, 6:25pm
2
@lisa Welcome Aboard!
Could you please share the below:
Expo or Bare Version:
Please take a look at our examples for your code
lisa
October 4, 2023, 8:37am
3
“react-native”: “0.71.11”
I have all object but idToken is empty
const config: SdkInitParams = {
clientId,
network: OPENLOGIN_NETWORK.SAPPHIRE_MAINNET
};
useEffect(() => {
async function init() {
try {
setIsLoading(true);
const web3AuthInstance = new Web3Auth(WebBrowser, EncryptedStorage, config);
setWeb3Auth(web3AuthInstance);
await web3AuthInstance.init();
if (web3AuthInstance) {
await getSession();
setIsLoadWeb3Auth(false);
}
} catch (error) {
setLoginError(error);
console.error(error);
} finally {
setIsLoading(false);
}
}
init();
}, []);
const login = async (
loginProvider: string,
callback?: (userInfo: any) => void,
login_hint?: string
) => {
try {
setIsLoading(true);
if (!web3Auth) {
console.log('web3auth not initialized yet');
return;
}
await web3Auth.login({
redirectUrl: resolvedRedirectUrl,
// mfaLevel: 'none',
loginProvider,
extraLoginOptions: {
login_hint
}
});
const info = web3Auth.userInfo();
console.log(web3Auth.ready);
const privKey = web3Auth.privKey;
console.log(privKey, 'privkey');
const wallet = await RPC.getAccounts(privKey as string);
setAddress(wallet);
setProvider(loginProvider);
const idToken = info?.idToken; // not idToken
console.log(info);
const isToken = await setAsyncStorage(STORAGE_KEYS.TOKEN, idToken);
getPubkey(idToken);
await setObjAsyncStorage(STORAGE_KEYS.INFO, info);
await setAsyncStorage(STORAGE_KEYS.PRIVATE_KEY, privKey);
await setAsyncStorage(STORAGE_KEYS.LOGIN_PROVIDER, loginProvider);
setKey(privKey);
if (callback && isToken) {
setToken(idToken);
callback({ ...info, wallet });
}
} catch (error) {
setLoginError(error);
console.error('Login error', error);
} finally {
setIsLoading(false);
}
};