Created
February 26, 2019 00:24
-
-
Save tdrach/7271bc0de8b09b49890156fbabec10c2 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
// lambda function in Netlify Functions to add "subscribed" role to user | |
const axios = require('axios') | |
function subscribeUser (url, token, id) { | |
return axios({ | |
method: `put`, | |
url: `${url}/admin/users/${id}`, | |
headers: { | |
'Authorization': `Bearer ${token}`, | |
'Content-Type': 'application/json', | |
}, | |
data: { | |
app_metadata: { roles: [`subscribed`] } | |
} | |
}).then(response => { | |
console.log("RESPONSE", response) | |
return response.json() | |
}).catch(error => { | |
console.log(error.response) | |
}) | |
} | |
exports.handler = function(event, context, callback) { | |
const data = JSON.parse(event.body) | |
return subscribeUser(data.url, data.token.access_token, data.id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting response: