Last active
June 27, 2021 05:51
-
-
Save yai333/abc104d9bf4cb11b6d4ca0f0f281983d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| const AWS = require('aws-sdk'); | |
| const dynamoClient = new AWS.DynamoDB.DocumentClient(); | |
| const crypto = require('crypto'); | |
| const headers = { | |
| 'Access-Control-Allow-Origin': '*', | |
| 'Access-Control-Allow-Credentials': true, | |
| }; | |
| module.exports.handler = async (event) => { | |
| const requestBody = JSON.parse(event.body); | |
| const { address } = requestBody; | |
| const response = await updateNonce(address); | |
| return { | |
| headers, | |
| statusCode: 200, | |
| body: JSON.stringify(response), | |
| }; | |
| }; | |
| const updateNonce = (address) => { | |
| const nonce = crypto.randomBytes(16).toString('hex'); | |
| const params = { | |
| TableName: process.env.USERTABLE_NAME, | |
| Key: { | |
| address, | |
| }, | |
| UpdateExpression: 'set nonce = :n', | |
| ExpressionAttributeValues: { | |
| ':n': nonce, | |
| }, | |
| ReturnValues: 'ALL_NEW', | |
| }; | |
| return dynamoClient.update(params).promise(); | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment