How to integrate web3auth on server, with Alchemy account kit?

Hello.
I’m trying to integrate web3auth with alchemy account kit.

Because alchemy account kit requires alchemy api key which should be secured, i’m trying to move my web3auth logic into server.
So when user successfully login, server will call web3auth.connect method and assign this client into alchemy account kit.

But the issue is that I can not create web3auth client on nodejs express server.
I did try to use this but it did not work.

the error message says

w3a-example/server/node_modules/.pnpm/@toruslabs+torus.js@12.2.0_@babel+runtime@7.24.1/node_modules/@toruslabs/torus.js/dist/torusUtils.cjs.js:670
            reject(new Error(msg));
                   ^

Error: Error occurred while verifying params unable to verify jwt token, [failed to verify jws signature: failed to verify message: crypto/rsa: verification error failed to verify jws signature: failed to verify message: crypto/rsa: verification error]
    at /Users/ggomma/test/w3a-example/server/node_modules/.pnpm/@toruslabs+torus.js@12.2.0_@babel+runtime@7.24.1/node_modules/@toruslabs/torus.js/dist/torusUtils.cjs.js:670:20
    at <anonymous>
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.10.0

my code

require('dotenv').config(); // enables loading .env vars
const express = require('express');
const app = express();
const cors = require('cors');
const pkg = require('@clerk/clerk-sdk-node');
const { EthereumPrivateKeyProvider } = require('@web3auth/ethereum-provider');
const { Web3Auth } = require('@web3auth/node-sdk');
const { CHAIN_NAMESPACES } = require('@web3auth/base');

const web3AuthConfig = {
  clientId:
    'BE0N5LlQDjLmc-...',
  verifier: 'w3a-node-demo',
};

const chainConfig = {
  chainId: '0x1', // Please use 0x1 for Mainnet
  rpcTarget: 'https://rpc.ankr.com/eth',
  chainNamespace: CHAIN_NAMESPACES.EIP155,
};
const web3auth = new Web3Auth({
  clientId: web3AuthConfig.clientId,
  web3AuthNetwork: 'sapphire_devnet', // Get your Network ID from Web3Auth Dashboard
  chainConfig,
});
const privateKeyProvider = new EthereumPrivateKeyProvider({
  config: { chainConfig },
});

const clerkClient = pkg.default;

app.use(cors({ origin: '*' }));
app.get('/api/hello', async (req, res) => {
  const privateKeyProvider = new EthereumPrivateKeyProvider({
    config: { chainConfig },
  });
  const verifier = 'auth-twitter';
  const verifierId = 'twitter|174493928...';
  const idToken = 'eyJhbGciOiJF...'; // obtained from web3auth
  await web3auth.init({ provider: privateKeyProvider });
  await web3auth.connect({
    verifier,
    verifierId,
    idToken,
  });
  return res.send('hello');
});

Hey @ggomma,

I hope you’re doing well!

I wanted to share some resources with you that might help. This are a guide an a example on how to connect Github Oauth with Web3auth

Here’s the link to the guide and examples:

I believe you’ll find them quite useful.
Looking forward to hearing from you and best of luck with your project!

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