The easiest should be to add a dropdown where the user can select, but I think you need to consider as to why the user would need more roles in this case. A superadmin should both be scout and player.
Dec 22, 2021
5
Level 8
Possible to select role on login
Hi!
I have a application made in laravel8.x and vue
Have this Logincontroller:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
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;
public function redirectTo()
{
//$rollen = Auth()->user();
$redirects = [
'Superadmin' => '/admin/dashboard',
'player' => '/player/dashboard',
'scout' => '/scout',
];
$roles = Auth()->user()->roles->map->title;
foreach ($redirects as $role => $url) {
if ($roles->contains($role)) {
return $url;
}
}
return '/login';
}
/**
* Create a new controller instance.
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
/**
* The user has logged out of the application.
*
* @return mixed
*/
protected function loggedOut(Request $request)
{
if ($request->wantsJson()) {
return response(null, Response::HTTP_NO_CONTENT);
}
}
}
What i want is:
If a user have more then 1 role, the user can select a role, before login.
Example:
role user
*********
Superadmin
player
scout
On login the user enter -> email, password and role (Superadmin,player,scout)
If example user select role->player The system login the user with role->player
How do i do this in laravel8.x/vue ?
Please or to participate in this conversation.