#Redirect To The Login Page

15 messages · Page 1 of 1 (latest)

smoky sonnet
#

okay so i used the laravel UI for the login and register and when the user login it redirect him to the dashboard i want when the user logout form the dashboard it will redirect him again to the login page but it redirect him to this page /home and says

Dashboard
You are logged in!

#

here is a video for more explain

#

i want it to redirect the user to the login page again

marsh basalt
#

Looks like you're not logging the user out then?

smoky sonnet
#

im sorry what do you mean?

#

when the user clicks on logout it redirect him again to the /home and says You are logged in!

#

here is the code of the login controller

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/dash';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        // Set a session variable with the user's name
        session(['userName' => $user->name]);
    }
}
marsh basalt
#

Like I said, you're probably not logging the user out?

smoky sonnet
#

okay how to fix it

#

i made this function in the HomeController but somehow it doesn't work

     * Log the user out of the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request)
    {
        Auth::logout(); // Log out the user

        $request->session()->invalidate(); 

        $request->session()->regenerateToken();

        return redirect('/login'); 
        
    }
}
marsh basalt
#

I guess make sure it's actually being hit

smoky sonnet
#

How?

#

i try everything but doesn't work it redirect me to the /home

rapid needle
#

check your network tab if it actually makes a request to your logout endpoint