Add Secret Token
Open server.js file and Insert your secret token that you have generated
app.post('/signup', async (req, res) => {
try {
const { email, password } = req.body;
//validate email using ApyHub API
const response = await axios.post('https://api.apyhub.com/validate/email/dns', { email }, {
headers: {
'apy-token': '***************ADD-YOUR-APY-TOKEN-HERE*****************', //
'Content-Type': 'application/json'
}
});
if (!response.data.data) {
return res.status(400).json({ message: 'Invalid email address' });
}
// Check if user already exists
const user = users.find(u => u.email === email);
if (user) {
return res.status(409).json({ message: 'User already exists' });
}
// Hash password
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds);
// Save user
users.push({ email, password: hashedPassword });
res.status(201).json({ message: 'User created' });
} catch (err) {
console.error(err);
res.status(500).json({ message: 'Internal server error' });
}
});
11
