Skip to main content

Proper Auth Controller: Login, Register: Logout

Premium
7:06

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

BM
Ben McKay ✓ Link copied!

I made a small change here that is probably worth noting.

In the logout function, I used the following:

$user = User::where('email', $request->email)->first(); // REMOVED THIS LINE
$user = Auth::user(); // ADDED THIS LINE

if($user) {
      $user->tokens()->delete();
}

return response()->noContent();

If I am reading the video code properly, User A could log out User B by putting in their email instead of their own. By doing it like I have above, you can only log yourself out.

MS
Mike Scott ✓ Link copied!

I was about to comment the same thing. The logout should be by access token in the authenticated group, with no need to pass in the email or any other parameter other than the bearer token.

S
Slon ✓ Link copied!

Logout must be inside the 'auth:sanctum' group, otherwise knowing any user's email you can logout him.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.