**Problem:**

I am very new to Hyperledger fabric. I create a network and enroll an admin to it using node sdk and then to register a user I create a script like this.

```
/*
 * SPDX-License-Identifier: Apache-2.0
 */

"use strict";

const {
  FileSystemWallet,
  Gateway,
  X509WalletMixin
} = require("fabric-network");
const fs = require("fs");
const path = require("path");

const ccpPath = path.resolve(__dirname, ".", "connection.json");
const ccpJSON = fs.readFileSync(ccpPath, "utf8");
const ccp = JSON.parse(ccpJSON);

async function main() {
  try {
    // Create a new file system based wallet for managing identities.
    const walletPath = path.join(process.cwd(), "wallet");
    const wallet = new FileSystemWallet(walletPath);
    console.log(`Wallet path: ${walletPath}`);

    // Check to see if we've already enrolled the user.
    const userExists = await wallet.exists("tharinduSA");
    if (userExists) {
      console.log(
        'An identity for the user "tharinduSA" already exists in the wallet'
      );
      return;
    }

    // Check to see if we've already enrolled the admin user.
    const adminExists = await wallet.exists("admin");
    if (!adminExists) {
      console.log(
        'An identity for the admin user "admin" does not exist in the wallet'
      );
      console.log("Run the enrollAdmin.js application before retrying");
      return;
    }

    // Create a new gateway for connecting to our peer node.
    const gateway = new Gateway();
    await gateway.connect(
      ccp,
      { wallet, identity: "admin", discovery: { enabled: false } }
    );

    // Get the CA client object from the gateway for interacting with the CA.
    const ca = gateway.getClient().getCertificateAuthority();
    const adminIdentity = gateway.getCurrentIdentity();

    // Register the user, enroll the user, and import the new identity into the wallet.
    const secret = await ca.register(
      {
        affiliation: "org1.department1",
        enrollmentID: "tharinduSA",
        role: "client"
      },
      adminIdentity
    );

    console.log(secret);
    const enrollment = await ca.enroll({
      enrollmentID: "tharinduSA",
      enrollmentSecret: secret
    });
    const userIdentity = X509WalletMixin.createIdentity(
      "Org1MSP",
      enrollment.certificate,
      enrollment.key.toBytes()
    );
    wallet.import("tharinduSA", userIdentity);
    console.log(
      'Successfully registered and enrolled admin user "user1" and imported it into the wallet'
    );
  } catch (error) {
    console.error(`Failed to register user "user1": ${error}`);
    process.exit(1);
  }
}

main();

```

But when I run this script It leaves me an error like this.

```
Failed to register user "user1": Error: Calling register endpoint failed with error [Error: unsupported certificate purpose]

```

When I debugging the code I was able to find out that code is failing at this point.

```
const secret = await ca.register(
      {
        affiliation: "org1.department1",
        enrollmentID: "tharinduSA",
        role: "client"
      },
      adminIdentity
    );

```

This is my connection.json file.

```
{
  "name": "basic-network",
  "version": "1.0.0",
  "client": {
    "organization": "Org1",
    "connection": {
      "timeout": {
        "peer": {
          "endorser": "300"
        },
        "orderer": "300"
      }
    }
  },
  "channels": {
    "mychannel": {
      "orderers": ["orderer.example.com"],
      "peers": {
        "peer0.org1.example.com": {},
        "peer0.org2.example.com": {}
      }
    }
  },
  "organizations": {
    "Org1": {
      "mspid": "Org1MSP",
      "peers": ["peer0.org1.example.com", "peer1.org1.example.com"],
      "certificateAuthorities": ["ca.org1.example.com"]
    },
    "Org2": {
      "mspid": "Org2MSP",
      "peers": ["peer0.org2.example.com", "peer1.org2.example.com"],
      "certificateAuthorities": ["ca.org2.example.com"]
    }
  },
  "orderers": {
    "orderer.example.com": {
      "url": "grpc://localhost:7050"
    }
  },
  "peers": {
    "peer0.org1.example.com": {
      "url": "grpc://localhost:7051"
    },
    "peer1.org1.example.com": {
      "url": "grpc://localhost:7051"
    },
    "peer0.org2.example.com": {
      "url": "grpc://localhost:7051"
    },
    "peer1.org2.example.com": {
      "url": "grpc://localhost:7051"
    }
  },
  "certificateAuthorities": {
    "ca.org1.example.com": {
      "url": "https://localhost:7054",
      "caName": "ca.org1.example.com"
    },
    "ca.org2.example.com": {
      "url": "https://localhost:7054",
      "caName": "ca.org2.example.com"
    }
  }
}

```

But I was unable to find out what is wrong with this. Can someone help me to solve this problem?. Thank you!!