Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access Auth::id() in asyncWidget #150

Closed
imran-drewl opened this issue Apr 30, 2021 · 3 comments
Closed

Unable to access Auth::id() in asyncWidget #150

imran-drewl opened this issue Apr 30, 2021 · 3 comments
Assignees

Comments

@imran-drewl
Copy link

HI @arrilot,

Thanks for this awesome widgets.

I'm facing an issue that when I use normal @widget I can can access authenticated user id in widget blade view using either auth()->user()->id or Auth::id() but not when use auto-reload or @asyncWidget.

I'm using laravel 8.*

I didn't published config file.

I have already seen this threat #102

and published config file in project there was already web middleware added in it.

I'm fetching data for widget from an API.

Thanks

@arrilot arrilot self-assigned this Jul 16, 2021
@FatihKoz
Copy link

Same/similar error happens with sync widgets too when public $reloadTimeout = 60; is being used ...

$user = Auth::user();
$name = $user->name_private;

Works just fine during initial run of the widget, but when the auto reload occurs "Trying to get property of non-object" exception is being returned for $user->name 'cause the Auth facade call fails or somehow returns null.

@arrilot
Copy link
Owner

arrilot commented Aug 21, 2021

I can't repoduce this.

  1. I've installed a fresh laravel 8 app using laravel new
  2. I've Added Laravel Breeze there
  3. Registred a user and logged in
  4. composer require arrilot/laravel-widgets
  5. php artisan make:widget Test
  6. user()->id ?> in the widget's view
  7. Placed widget at dashboard
  8. Both @widget and @asyncWIdget both give me correct id. If I add $reloadTimeout = 2 they both still work as intented.

My guess: you did somthing with middleware in your apps.
If you can make a similar reproduction and post it to github I can give it another try

@arrilot arrilot closed this as completed Aug 21, 2021
@FatihKoz
Copy link

Yes, it was related with the middleware ... Sorry not reporting that earlier, web must be defined/allowed in the middleware for laravel-widgets.

The main app's developer figured it out and with an update to the core app my addon widgets started working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants