Skip to main content

Authenticating with the Edge Client

Certain actions on the Edge Client will require your users to be authenticated. We recommend authenticating your players before attempting to perform game actions using the Edge Client.

You'll need to first create a Honeycomb user before authenticating using the information below.

Authenticating with the Edge Client

Authentication using Edge Client is a 2 step process. First, send an auth request query like this:

const { 
authRequest: { message: authRequest }
} = await client.authRequest({
userPublicKey.toString()
});

In return you'll get a response like this:


{
"data": {
"message": "Please sign this message to authenticate to Honeycomb unified interface: 3CzXyQb2NVuXaKuQJ26FTqWcdXxirGvbJ2RNPpXCA9Mj"
}
}

Next, you will need sign this message:

import { useWallet } from "@solana/wallet-adapter-react";
import base58 from "bs58";

// Get the user's wallet
const wallet = useWallet();
// Convert the auth request into a UInt8Array
const encodedMessage = new TextEncoder().encode(authRequest);
// Sign the message
const signedUIntArray = await wallet.signMessage(encodedMessage);
// Convert the signed message into a base58 encoded string
const signature = base58.encode(signedUIntArray);
// Send the signed message to the server
const { authConfirm } = await client.authConfirm({ wallet: userPublicKey.toString(), signature });

After you've sent the signed message to the server, you'll get an access token and a user object containing the details of the user. You can use the access token to authenticate the user in subsequent requests. Here's an example:

const { createNewProfileTransaction: txResponse } =
await client.createNewProfileTransaction(
{
project: projectAddress,
info: {
name: `Test profile`,
bio: `This is a test profile`,
pfp: "https://www.example.com/pfp.png",
},
payer: userPublicKey.toString(),
},
{
fetchOptions: {
headers: {
authorization: `Bearer ${accessToken}`,
},
},
}
);