<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    /**
     * Arahkan user setelah login sesuai role
     */
    protected function redirectTo()
    {
        if (auth()->user()->role == 'admin') {
            return '/admin/home';
        } elseif (auth()->user()->role == 'user') {
            return '/user/home';
        } else {
            return '/home';
        }
    }

    /**
     * Jika login gagal karena belum dikonfirmasi
     */
    

    public function logout()
    {
        Auth::logout();
        return redirect('/');
    }
}
