How to check in the API if a user being searched in the database is the user who is logged in?

Asked

Viewed 262 times

0

I am using Laravel and I need to create an attribute (is_me) in the model to know if the current profile belongs to the user who is logged in;

I was doing as below, but now that I am using API I can no longer use Auth::user()

public function getIsMeAttribute(){
    return \Auth::user()->id == $this->id;
}
  • How do you authenticate your user? JWT? Oauth? How is the security of your API?

  • I’m using the token method - I’m not sure if this fits Oauth

  • So this token is probably related to the user who is authenticated, right? If it would not be interesting to do so, when generating the token relate to the user, this way before performing the test you put in code, search the user authenticated by the token and then test if the ids are equal

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.