Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aziashary's avatar

Looping on login page breeze laravel 8

I have 2 login page, which one for admin and another one for user, i have to seperate login page for security reason. The first login page (default breeze login page) are working. the second one too are working but its doing looping on login page when i pass the authenticaton. i know its working because i do debug and the result is true.

auth/config.php

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'hash' => false,
        ],
        'warga' => [
            'driver' => 'session',
            'provider' => 'warga',
        ],
    ],

logincontroller.php

public function login(Request $request)
    {
        // $this->validator($request);
        
        if(Auth::guard('warga')->attempt($request->only('nik','password'),$request->filled('remember'))){
            //Authentication passed...
            return redirect()
                ->intended(route('warga.home'))
                ->with('status','You are Logged in as warga!');
        }
    
        //Authentication failed...
        return redirect()->back()->withErrors([
            'nik' => 'nik atau password yang Anda masukkan salah',
        ]);
    }

authenticated.php

protected function redirectTo($request)
    {
        if (!$request->expectsJson()) {

            if(Route::is('warga.*')){
                return route('warga.login');
            }
    
            return route('login');
        } else {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }
    }

route web.php

Route::get('/dashboard',[HomeController::class, 'index'])->name('home')->middleware('auth:warga');
warga-login.php

<x-guest-layout>
    <x-auth-card>
        <x-slot name="logo">
            <a href="/">
                <x-application-logo class="w-20 h-20 fill-current text-gray-500" />
            </a>
        </x-slot>

        <!-- Session Status -->
        <x-auth-session-status class="mb-4" :status="session('status')" />

        <!-- Validation Errors -->
        <x-auth-validation-errors class="mb-4" :errors="$errors" />

        <form method="POST" action="{{ url('warga/login-auth') }}">
            @csrf

            <!-- nik Address -->
            <div>
                <x-label for="nik" :value="__('NIK')" />

                <x-input id="nik" class="block mt-1 w-full" type="text" name="nik" :value="old('nik')" required autofocus />
            </div>

            <!-- Password -->
            <div class="mt-4">
                <x-label for="password" :value="__('Password')" />

                <x-input id="password" class="block mt-1 w-full"
                                type="password"
                                name="password"
                                required autocomplete="current-password" />
            </div>


            <div class="flex items-center justify-end mt-4">
                @if (Route::has('password.request'))
                    <a class="underline text-sm text-gray-600 hover:text-gray-900" href="{{ route('password.request') }}">
                        {{ __('Forgot your password?') }}
                    </a>
                @endif

                <x-button class="ml-3">
                    {{ __('Log in') }}
                </x-button>
            </div>
        </form>
    </x-auth-card>
</x-guest-layout>

all of the login page are similar but im using different form, the first one is "username" and the second one is "NIK"

Thanks for helping

0 likes
1 reply

Please or to participate in this conversation.