Coder Social home page Coder Social logo

Comments (3)

cedlinx avatar cedlinx commented on September 28, 2024

I encountered the same issue using this in my REST API... A workaround would be highly appreciated

from laravel-timezone.

cedlinx avatar cedlinx commented on September 28, 2024

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.

obrunopolo avatar obrunopolo commented on September 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.