Uncaught SyntaxError: Unexpected token '!' and Uncaught TypeError: Cannot read property 'isLoggedin' of undefined
bhojkamal opened this issue · 5 comments
Hello, first of all thanks for making the available of laravel spa vue 3 auth crud.
However, I have followed you and setup on my local, but it didn't display anything on the browser? There are couple of error on console.
The first one is -
Uncaught SyntaxError: Unexpected token '!'
This come from app.blade.php in
window.Laravel = {
!!json_encode([
'isLoggedin' => true,
'user' => Auth::user()
]) !!
}
What is the function of !!json_encode? and why are you using window.Laravel, I hope there is better way.
The second one is from App.vue - The error on console is
Uncaught TypeError: Cannot read property 'isLoggedin' of undefined
And the reason not displaying anything on browser is, I think, - the warning on console.
[Vue warn]: Unhandled error during execution of created hook
at <App>
If we can fix this warning, I think it should work.
I hope you have solutions for this.
Regards.
Also upgrade bootstrap 5 and remove jquery please.
I change the code in app.blade.php to
<script> window.Laravel = '<?= json_encode([ 'isLoggedin' => true, 'user' => Auth::user() ]); ?>' </script>
So No error now, only one minor warning. I am able to register too. and and when login to it, isLoginIn is true, and user details is seen on by above code but it is not redirected to the dashboard. It is still on login page and we can open register page. but if we open dashboard or books, it redirect back to login page, why?
I hope you will find the error.
Thanks
Hi @bhojkamal,
I'm extremely sorry. I was so busy with many tasks and didn't give my attention to my blog and comment.
Did you able to fix the issue? If not I'll help you. I'm sorry again, bro.
Hi @bhojkamal,
I replied to your comments. Please have a look https://shouts.dev/laravel-spa-with-vue3-auth-crud-example
Thanks.
Thank you very much for you resources. I was able to fix it. My vs code prettier d-formatted on save the unescaped data. and got error. I added laravel blade syntax highlighter extension now and it's working without error.
{!! $var !!}
to
{
!!
$var
!!
}
and it was not working. I was struggling a bit for 2 days for it and fixed this issue and worked.
Great bro. Glad to hear that.
I also updated the article (Step 5). I hope it'll be helpful.
Thank you so much for letting me know the issue.
Have a good day. 👍