Skip to content

Instantly share code, notes, and snippets.

@tdrach
Created February 26, 2019 00:24
Show Gist options
  • Save tdrach/7271bc0de8b09b49890156fbabec10c2 to your computer and use it in GitHub Desktop.
Save tdrach/7271bc0de8b09b49890156fbabec10c2 to your computer and use it in GitHub Desktop.
// 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)
}
@tdrach
Copy link
Author

tdrach commented Feb 26, 2019

Getting response:

data: { code: 401, msg: 'User not allowed' } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment