Laravel(API) + Angular 5 - How to log out user

Posted 6 months ago by nikoslykos

Because i dont use the default laravel authentication but a custom authcontroller, how do i logout a user? This is the code from the AuthController. Then Angular Takes the XSRF Token and is logged in. How do i logout? Can i use auth::logout ? Or it doesnt work that way? Do i have to destroy the token? If yes how?

namespace App\Http\Controllers; 
use App\User; 
use Illuminate\Http\Request; 
use App\Http\Controllers\Controller; 
use Illuminate\Support\Facades\Auth; 
use Validator; 
class AuthController extends Controller 
    public function login(Request $request) 
        Auth::attempt(['email' => request('email'), 'password' => request('password')]); 
        return redirect('/auth_status'); 
    public function authStatus()  
        if (Auth::check()) { 
            return response()->json(['Authenticated' => true]); 
            return response()->json(['Authenticated'=> false]); 
    public function register(Request $request) 
        $validator = Validator::make($request->all(), [ 
            'email' => 'required|email', 
            'password' => 'required' 
        if ($validator->fails()) { 
            return response()->json(['error'=>$validator->errors()], 401);             
        $input = $request->all(); 
        $input['password'] = bcrypt($input['password']); 
        $user = User::create($input); 
        $success['name'] =  $user->name; 
        return response()->json(['success'=>$success], $this->successStatus);     

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.