I’m working in project which require to use third party APIs
some functions in the api require authentication so I’m using JWT tokens
here is APIs Authentication flow and the problem i get when using moralis
The code I’m using for this flow
// the generateChallenge and authenticate is created in another file
// `signMessageAsync` lets us programatically request a message signature from the user's wallet
const { signMessageAsync } = useSignMessage();
// authenticate method from moralis
const {authenticate, account} = useMoralis()
// sign in function
const signIn = async () => {
try {
// check if there is no connected address
if (!account) {
return alert('Please connect your wallet first');
}
//I'm using user address to generate challenge
const challenge = await generateChallenge(account);
//I'm using user address to sign message
const signature = await signMessageAsync({message : challenge });
// I'm getting access token
const accessToken = await authenticate(account, signature);
console.log( {accessToken});
// I'm user access Token sessionStorage
window.sessionStorage.setItem('accessToken', accessToken);
} catch (error) {
console.error(error);
alert('Error signing in');
}
};
The problem I’m facing
when I hit the signIn button meta mask pops-up to sign message
The problem starts here
after clicking Sign Button the metamsk pop-up again to sign the moralis message see here
so instead of getting the lens API access tokens it returns moralis access token / perserUser object
What I’m looking for is to make sure the metamask pop’s up once / one time to sign the message from lens API
then return the access token from lens api