[SOLVED] ERROR : NextJS 14 Solana authentication fails

Hi,

I am trying to implement Solana authentication with NextJS 14 using the dedicated package “@moralisweb3/next”. Currently the only version working with Solana/NextJS is the version “2.8.2” that is outdated for a year

Maybe I am doing something wrong but I don’t know.

For anyone to try and avoid NextJS 14 App router complexity, you can clone the official tutorial repo : nextjs_solana_auth_api

This use “@moralisweb3/next” v2.8.2 and works perfectly. But if you upgrade the “@moralisweb3/next” package (run npm install @moralisweb3/next@latest) you will not be able to authenticate. You will have this error :

“Error: Operation requestChallengeSolana has no requestHandler in auth”

The latest package of “@moralisweb3/next” is “2.24.0” but even if you try to update the package to the following version of 2.8.2 which is 2.9.0 (deprecated for a year now) it won’t work.

I really need your help, because to make it work I am using the old deprecated version and I cannot use “@moralisweb3/next” for anything except authentication cause it is outdated.

Hi @Kroustof90

It seems like I was able to run this without any error even after upgrading. The only change I made was updating the next js package to version 12.2.5 and to the latest @moralisweb3/next package

After adding the required .env variables I ran the project on localhost 8000 port and it worked as expected.

Maybe can you try adding any console.logs for the request challenge function params?

That might give us more idea on what is happening

Thank you for the answer. I am sorry but I still have this error. Can you share the updated repo please ? Because I am doing something wrong and I don’t know what.

I pushed the changes to the same repository. You can check now🙌

Have you try this specific repo : https://github.com/JohnVersus/solana-nft-gating-auth.git

It is the Solana authentication that fails.

Ok I am going to try it

1 Like

Yes, thats the same repository where I tested.

SORRY !

I gave you the wrong repo


this is the one : https://github.com/JohnVersus/nextjs_solana_auth_api.git

My bad. Can you update this one ? Because it use wallet adaptor and phantom

Ahh ok. Let me have a look at it.

The repo you updated works well but it does not use useAuthRequestChallengeSolana() on client and MoralisNextAuthProvider() on backend api route [
nextauth].ts, from @moralisweb3/next package

I have pushed some changes to the github repo. Please test it. It should work now.

Thank you! I just tested it and it worked. Although, there is a little error on WalletAdaptor logic, you inverted the value of chain and network which cause an error during authentication.

Also, I wanted to know. You changed your approch on authentication by adding request-message.js, so that means that the package “@moralisweb3/next” is currently not working correctly with solana authentication ?

The authentication logic internally user Moralis auth API which requires using request message endpoint.
You can find the auth logic details on the below page

Are you still seeing any error? If yes, please share how to reproduce the error.

Ok thank you very much for your help ! Problem solved. :grinning:

The error is in walletAdaptor.js :

const signCustomMessage = async () => {
    const address = publicKey.toBase58();
    const chain = "devnet";
    const account = {
      address: address,
      chain: chain,
      network: "solana",
    };
... 

The correction here :

const signCustomMessage = async () => {
    const address = publicKey.toBase58();
    const chain = "solana";
    const account = {
      address: address,
      chain: chain,
      network: "devnet",
    };

That’s it. But if someone use the repo and not see it there will be an error for wallet adaptor authentication.

Blockquote The authentication logic internally user Moralis auth API which requires using request message endpoint.
You can find the auth logic details on the below page

What I meant is that useAuthRequestChallengeSolana() from @moralisweb3/next does not work anymore.

Thank you. I have updated the code to fix this🙌

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.