I am using netlify identity and want to protect API routes for non-logged in users. Issue is that in context.clientContext
in custom function is doesn’t return any user info.
Site URL https://transcendent-pegasus-7ff91f.netlify.app as you can see login and logout is working fine but if you go to https://transcendent-pegasus-7ff91f.netlify.app/.netlify/functions/data which is a function which will return data and user info but it’s not sending any user info.
const handler = async function (event, context) {
const { identity, user } = context.clientContext
console.log(user)
const data = { value: '###' }
return {
statusCode: 200,
body: JSON.stringify({ identity, user, msg: data.value }),
}
} catch (error) {
console.log(error)
return {
statusCode: 500,
// Could be a custom message or object i.e. JSON.stringify(err)
body: JSON.stringify({ msg: error.message }),
}
}
}
module.exports = { handler }
Also console.log(user)
outputs undefined
.
What’s the possible reason?