andyleach / vue-flash

A flash messaging component for Vue.js
MIT License
45 stars 4 forks source link

Message doesn't appear #13

Closed espositodaniele closed 7 years ago

espositodaniele commented 7 years ago

Hello,

I'm trying to use it with Laravel Framework and all I want to do is to flash a message after the user logged in. I can't figure out how to call it from PHP if a session is set. I have tried to call it between the script tag if a session is set and I don't think is best practices to follow.

Thanks

andyleach commented 7 years ago

Are you only intending to provide an alert to show someone that they are logged in or will there be other alerts?

espositodaniele commented 7 years ago

Actually, I have other alerts, but they are fired when someone on that page will add some resource, for example: adding a post or editing. I'm facing this problem because I want to fire a flash a message from javascript in a blade template and I don't have any event running in javascript at the moment the users log in. I'm just getting in the admin area from login controller.

Thanks

andyleach commented 7 years ago

You could run a check on /api/user and see if a user model is returned

espositodaniele commented 7 years ago

So are you saying that I should make an ajax call to API/user to see if someone is logged in? Uhmm I don't really know it can be an elegant way to solve it... but can be an option.

Thanks

andyleach commented 7 years ago

Is the login process being handled by Ajax?

espositodaniele commented 7 years ago

No is not. It is the simple process of Laravel "auth" that provides to use in a really easy way to start. I know If I do it with ajax I can call the flash method on the success request, but is not what I'm trying to achieve.

andyleach commented 7 years ago

You could probably do something like this:

<script>
const loggedIn = json_encode(Auth::check());
</script>
espositodaniele commented 7 years ago

And then on page load, I should check if the logged in is set right? If so, on every page load of the dashboard I wil get the message.

andyleach commented 7 years ago

Are you using Vue for a SPA?

espositodaniele commented 7 years ago

Nope. As I said before I'm just using the laravel auth. I'm figuring out that is actually not possible.

andyleach commented 7 years ago

Yeah, there isn't really a clean/elegant way to handle this that I can think of.