appkit icon indicating copy to clipboard operation
appkit copied to clipboard

[bug] NextJS Middleware does not work with Appkit

Open tpalaz opened this issue 1 year ago • 3 comments

Link to minimal reproducible example

https://github.com/tpalaz/reown-appkit-middleware

Summary

Overview:

When using NextJS middleware and setting up subdomains for your app - which is an extremely common use case - appkit doesn't work as expected and leads to some strange bugs. This is not an issue related to NextJS, and I believe has to do with how appkit manages localstorage.

Primarily, the Phantom wallet prompt does not show up, despite being detected and instead hangs up on "Continue in Phantom Accept connection request in the wallet" . However, Metamask / EVM does seem to work.

Reproduce:

  1. Set up a NextJS application with middleware to handle subdomain routing
  2. Configure AppKit with both Wagmi and Solana adapters
  3. Create authentication pages on the subdomain (wallet connection stuff)

Investigation Findings

Analysis of localStorage and cookies between domains reveals:

@appkit/active_caip_network_id:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
@appkit/active_namespace:"solana"
@appkit/connection_status:"connecting"
@appkit/solana:connected_connector_id:"walletConnect"

On localhost:3000, AppKit sets:

@appkit/active_caip_network_id:"eip155:1"
@appkit/active_namespace:"eip155"
@appkit/connection_status:"disconnected"

This issue significantly impacts applications that:

  • Use domain-driven design with subdomains (a common pattern in NextJS applications)
  • Need to support multi-chain functionality including Solana
  • Require consistent authentication flows across subdomains

The attached repo is boiler-plate generated from the appkit CLI, with the addition of a basic middleware.

List of related npm package versions

"@reown/appkit": "1.6.9", "@reown/appkit-adapter-solana": "1.6.9", "@reown/appkit-adapter-wagmi": "1.6.9", "@solana/wallet-adapter-wallets": "^0.19.32", "@solana/web3.js": "^1.98.0", "@tanstack/react-query": "5.62.8", "next": "15.1.3", "react": "19.0.0", "react-dom": "19.0.0", "viem": "^2.21.44", "wagmi": "^2.12.31"

Node.js Version

v18.20.2

Package Manager

[email protected]

tpalaz avatar Mar 10 '25 23:03 tpalaz

hi @tpalaz I hope you are doing good . the ProjectId -> d5445347a993fd238ed924fb71e19e1a is just for testing in localhost.

You can create a new one in https://cloud.reown.com/ and allow the domain : *.localhost:3000

rtomas avatar Mar 12 '25 18:03 rtomas

Thanks rtomas,

I am aware of the projectID being localhost testing, I left it in there to not expose mine / hard coded to make it easy for someone to clone and replace.

Upon further investigation, I believe this issue is related to Solana's wallet connector lib or a more specific NextJS middleware issue, and not specific to AppKit.

tpalaz avatar Mar 12 '25 18:03 tpalaz