Comments (3)
I encountered the same issue using this in my REST API... A workaround would be highly appreciated
from laravel-timezone.
I encountered the same issue using this in my REST API... A workaround would be highly appreciated
I found the source of the error:
The handle function in
"...vendor/jamesmills/laravel-timezone/src/Listeners/Auth/UpdateUsersTimezone.php"
Then found "loginUsingId" in the first IF block
`
if ($event instanceof AccessTokenCreated) {
Auth::loginUsingId($event->userId);
return;
}
`
and replaced
Auth::loginUsingId($event->userId);
with
$user = User::find($event->userId);
DO NOT forget to include your user model at the begining of the file like this
use App\Models\User;
I also had to comment out the return statement in the IF block above before my change had any effect.
PS: I believe this is safe since according to the comment in the file, that IF block is required ONLY to trigger the the Login Event which in turn only returns the user object. If anyone finds a better solution, I'd be glad to use it, but for now, this works for me besides the fact that my timezone is wrongly captured.
from laravel-timezone.
I encountered a similar issue, and cedlinx provided a helpful workaround. In my case, I had a function for support where authorized people could access user accounts. I could get this error when calling an API using the Laravel\Passport\HasApiTokens::createToken
method. This dispatches an AccessTokenCreated
event, which calls Auth::loginUsingId
, triggering the error.
Following cedlinx's suggestion, I found that the source of the error lies in the handle
function within vendor/jamesmills/laravel-timezone/src/Listeners/Auth/UpdateUsersTimezone.php
. Inside the function, there is an if
block with the following code:
if ($event instanceof AccessTokenCreated) {
Auth::loginUsingId($event->userId);
return;
}
cedlinx proposed a workaround by replacing the line Auth::loginUsingId($event->userId)
with $user = User::find($event->userId)
. Additionally, they mentioned the need to include the user model at the beginning of the file using use App\Models\User;
.
It's important to note that before the proposed change takes effect, the return
statement within the if
block needs to be commented out.
I appreciate cedlinx's contribution, as this workaround resolved the issue for me. However, I'm open to other suggestions or alternative solutions from the community.
from laravel-timezone.
Related Issues (20)
- Carbon diffForHumans
- PHP 8 Support? HOT 1
- Usage of protected instead of private function HOT 2
- Crashing Passport HOT 2
- Daylight savings (CET vs CEST?) HOT 3
- 'time_zone' instead of 'timezone' HOT 2
- Server 500 error when used with laravel octane / swoole
- Add timezone select to Jetstream profile page? HOT 1
- Updating wrong timezone automatically add manual feature HOT 4
- The library does not take the first found IP from 'lookup' config key HOT 1
- Formatting dates HOT 7
- Use language files HOT 1
- Inertia support HOT 1
- Laravel 10 support update please. HOT 3
- Laravel 10 future support. HOT 9
- Laravel 10 issue... HOT 8
- Replace the geoip with a better-maintained package HOT 13
- Issue with require HOT 4
- Laravel 11 Support HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-timezone.