In laravel 9 Inertiajs/vuejs when unlogged user select admin area with typing url in browser, like
site/admin/currencies
Login page is opened and on submit I redirect to default user depending on access of user in JS code:
function loginSubmit() {
formLogin.value.post(route('login'), {
preserveScroll: true,
onSuccess: (data) => {
if(usePage().props.value.auth.is_logged_user_admin) {
Toast.fire({
icon: 'success',
title: 'You are logged into the app as admin'
})
window.location.href= route('admin.dashboard.index')
return
} // if(usePage().props.value.auth.is_logged_user_admin) {
if(usePage().props.value.auth.is_logged_user_content_editor) {
Toast.fire({
icon: 'success',
title: 'You are logged into the app as content editor'
})
window.location.href= route('admin.cms_items.index')
return
} // if(usePage().props.value.auth.is_logged_user_content_editor) {
// ...
But actually I see that at first site/admin/currencies page is opened and only after that site/admin/dashboard is opened if logged user is admin.
How can I cancel site/admin/currencies page opening?
UPDATED BLOCK: As I use Fortify in file app/Providers/FortifyServiceProvider.php I have :
<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use App\Models\User;
use Carbon\Carbon;
// app/Providers/Responses/LoginResponse.php
//use App\Http\Responses\LoginResponse;
//use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
Fortify::authenticateUsing(function (Request $request) {
$user = User::where('email', $request->email)->first();
$request = request();
if ($user && Hash::check($request->password, $user->password)) {
if ($user->status === 'A') {
return $user;
} else {
throw ValidationException::withMessages([
Fortify::username() => "Account is not active",
]);
}
}
});
RateLimiter::for('login', function (Request $request) {
$email = (string) $request->email;
return Limit::perMinute(5)->by($email.$request->ip());
});
RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
}
}
I suppose default Fortify login functionality is called with this default action. I do not have any other files edited. How can it be overwritten/cancelled ?