netlify-cli
Version:
Netlify command line tool
37 lines (30 loc) • 1.06 kB
JavaScript
const fetch = require('node-fetch')
const handler = async (event, context) => {
if (event.httpMethod !== 'POST') return { statusCode: 400, body: 'Must POST to this function' }
// send account information along with the POST
const { email, password, full_name: fullName } = JSON.parse(event.body)
if (!email) return { statusCode: 400, body: 'email missing' }
if (!password) return { statusCode: 400, body: 'password missing' }
if (!fullName) return { statusCode: 400, body: 'full_name missing' }
// identity.token is a short lived admin token which
// is provided to all Netlify Functions to interact
// with the Identity API
const { identity } = context.clientContext
await fetch(`${identity.url}/admin/users`, {
method: 'POST',
headers: { Authorization: `Bearer ${identity.token}` },
body: JSON.stringify({
email,
password,
confirm: true,
user_metadata: {
full_name: fullName,
},
}),
})
return {
statusCode: 200,
body: 'success!',
}
}
module.exports = { handler }