A Next.js application with SIWE (Sign-In with Ethereum) authentication integrated with a Drupal backend.
- SIWE authentication flow with Ethereum wallet integration
- JWT token-based authentication with Drupal backend
- User account creation and management in Drupal
- CORS support for cross-origin requests
- Article creation and viewing functionality
- Install dependencies:
npm install - Configure environment variables in
.env.local:NEXT_PUBLIC_DRUPAL_BASE_URL- The base URL of your Drupal siteDRUPAL_CLIENT_ID- The client ID for Drupal authenticationDRUPAL_CLIENT_SECRET- The client secret for Drupal authentication
- Start the development server:
npm run dev
The following environment variables are required:
NEXT_PUBLIC_DRUPAL_BASE_URL- The base URL of your Drupal site (e.g., https://drupal.ddev.site)DRUPAL_CLIENT_ID- The client ID for Drupal authenticationDRUPAL_CLIENT_SECRET- The client secret for Drupal authentication
- User clicks "Sign in with Ethereum" button
- The application requests access to the user's Ethereum wallet
- A nonce is retrieved from the Drupal backend
- A SIWE message is created and signed by the user's wallet
- The signed message is sent to the Drupal backend for verification
- If verification is successful, JWT tokens are returned
- The JWT tokens are stored in local storage for subsequent requests
SiweLogin- A React component that handles the SIWE authentication flowWagmiProvider- Provides Ethereum wallet integration (if using wagmi)
siwe- For creating and parsing SIWE messagesethers- For Ethereum wallet integrationnext-drupal- For communicating with the Drupal backenddate-fns- For formatting dates
If you encounter CORS issues, make sure the Drupal backend is configured to allow requests from your Next.js application's origin. The siwe_server module includes CORS configuration that can be modified in the Drupal admin interface.
The application automatically converts Ethereum addresses to EIP-55 checksum format to ensure compatibility with the Drupal backend.
The application handles JWT token expiration by providing a refresh token that can be used to obtain a new access token.
The application includes functionality for creating and viewing articles:
/- View a list of all articles (front page)/articles/create- Create a new article (requires authentication)/[article-slug]- View a single article (e.g., /my-article-title)/articles/[id]- View a single article by ID (redirects to slug URL)
See https://next-drupal.org for more information about Next.js for Drupal.