Created
September 13, 2022 10:02
-
-
Save pazel-io/b496fa29176f9e6fa1f5f770e817f804 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Handler that will be called during the execution of a PreUserRegistration flow. | |
* | |
* @param {Event} event - Details about the context and user that is attempting to register. | |
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup. | |
*/ | |
const axios = require('axios'); | |
exports.onExecutePreUserRegistration = async (event, api) => { | |
const deviceSerialNumber = event.user?.user_metadata?.deviceSerialNumber; | |
let isValidSN = false; | |
const checkDeviceSN = async (deviceSerialNumber) => { | |
const apiKey = event.secrets.API_KEY; | |
const url = `https://api.example.com/v1/devices/${deviceSerialNumber}`; | |
const headers = { | |
'api-key': apiKey, | |
'Content-Type': 'application/json' | |
}; | |
const response = await axios.get(url, { headers }); | |
return response.data.isValid; | |
} | |
if(deviceSerialNumber){ | |
// make a http call to your api and check the device SN | |
isValidSN = await checkDeviceSN(deviceSerialNumber); | |
} | |
if(!isValidSN){ | |
return api.access.deny('Invalid device serial number', 'You need to provide a valid device serial number') | |
} | |
api.user.setAppMetadata('deviceCheckPassed', true) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment