I am using Axios for my client-side requests. For example:
- Logged in client requests DELETE
- Router pipes through Auth plug
- Auth plug checks if conn.assigns has user
- If user exists and has role, delete-action is executed
This works without problems in DEV-mode. The conn.assigns holds my user_id and the request is executed. In PROD-mode, my conn.assigns is empty. I really don’t see the cause of the problem. Could this be caused by my CDN (Cloudflare)?
JS:
axios ({
method: 'delete',
url: `${Url.value}/removeRegion/${region}`,
headers: {
'X-Requested-With': 'XMLHttpRequest',
'x-csrf-token': document.head.querySelector("[name~=csrf-token[content]").content
}
})
Controller:
plug :authenticate when action in [....]
def authenticate(conn, _opts) do
assign = conn.assigns
if conn.assigns.current_user && conn.assigns.current_user.admin do
conn
else
Logger.debug "NO AUTH!!"
–> This errors out since conn.assigns is empty