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

Published 4 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?

<?php 
 
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]); 
        } 
        else  
            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);     
    } 
 
} 

Dry7
Dry7
4 months ago (152,030 XP)

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