The following approach has been suggested in a few SO answers as a way of passing authenticated user details from backend (PHP/Laravel) to frontend (JavaScript/Vue). However, I would like to confirm how secure it is.
<script>
window.App = {!! json_encode([
'user' => Auth::user()
]); !!};
</script>
Are there any security implications of passing authenticated user details to JavaScript using this approach assuming details do contain user-generated input like name and username? Can JavaScript code safely handle this data to authorize user actions and/or output any of this data as HTML?
Or is there anything that a user can type into Name/Username fields during registration that can break this code / pose a security concern? Is there any benefit in sanitizing output of json_encode() before passing it to JavaScript?
EDIT
As an example, let's say I get this data from the server, pass it to JavaScript using json_encode() and then output user name in HTML using JavaScript. Can this be exploited in any way if users are allowed to enter anything (up to a certain char limit) into the Name field during registration?