Integrating Authentication API with AWS Lambda

Could you guide me how to integrate Authentication API with AWS Lamda for non-game developers as well?

someone should be able to help you, I don’t know the exact details now for using AWS lambda.

in theory you only have to make a request to Auth API to get a message for the user to sign after you know the user wallet address (that could be one request to an aws lambda endpoint), after you get that message to be signed then you sign it in front end with metamask (this step can be done with a custom code that signs a message), then you send the message and the signature to the backend (aws lambda function) where you validate the signature by making a request again to Auth API, after the signature is validated you have to store somewhere some information about the user if you want to store it and to return to front end a session token that represents the confirmation that the authentication was done successfully

Updated: No! Only the half is done. Verify EVM challenge is not set yet.

It worked. This is the final code in Lambda function.
Thanks everybody!

const axios = require('axios');

exports.handler = async (event) => {
  try {
    const moralisApiKey = process.env.MORALIS_API_KEY;
    const moralisAuthApiUrl = 'https://authapi.moralis.io/challenge/request/evm';
    console.log('Event body:', event.body);
    const parsedEventBody = JSON.parse(event.body);

    if (!parsedEventBody || !parsedEventBody.address) {
      throw new Error('Address not provided in the event body.');
    }

    const inputAddress = parsedEventBody.address;

    const response = await axios.post(moralisAuthApiUrl, {
      domain: "vevel.xyz",
      chainId: 1,
      address: inputAddress,
      statement: "Please confirm",
      uri: "https://vevel.xyz/",
      timeout: 15
    }, {
      headers: {
        accept: "application/json",
        "X-API-Key": moralisApiKey,
        "content-type": "application/json"
      }
    });

    const responseBody = {
      message: "Moralis authentication request successful",
      response: response.data
    };
    const lambdaResponse = {
      statusCode: 200,
      body: JSON.stringify(responseBody),
    };
    return lambdaResponse;
  } catch (error) {
    console.error('Error:', error);
    const lambdaResponse = {
      statusCode: 500,
      body: JSON.stringify({
        message: 'Error during authentication.',
        error: error,
      }),
    };
    return lambdaResponse;
  }
};

3 Likes