hesto / multi-auth Goto Github PK
View Code? Open in Web Editor NEWLaravel 5.3, 5.4, 5.5, 5.6, 5.7 multi auth package
License: MIT License
Laravel 5.3, 5.4, 5.5, 5.6, 5.7 multi auth package
License: MIT License
I have added this in. Changed the login page to reflect my own layout as well as the register page.
I can register and login fine but when I click logout its not logging me out. It takes me back to the root but if I visit the login page again then I see that I am actually logged in.
Is there something I need to add to log out a user?
i follow the tutorial till the end but when i want to type "php artisan multi-auth:install admin -f"
i keep getting these error.
[Illuminate\Contracts\Filesystem\FileNotFoundException]
File does not exist at path C:{MY_LARAVEL_DIRECTORY}/routes/web.php
i currently use laravel 5.3
thank you
Hi Hesto,
I got an idea to create grouping routes prefix in multi-auth/src/stubs/routes/web.stub
//{{singularClass}} Group Routes
Route::group(['prefix' => '{{singularSlug}}'], function () {
//routes: [project]/{{singularSlug}}
//{{singularClass}} Login
Route::get('', '{{singularClass}}Auth\LoginController@showLoginForm');
Route::get('/login', '{{singularClass}}Auth\LoginController@showLoginForm');
Route::post('/login', '{{singularClass}}Auth\LoginController@login');
Route::post('/logout', '{{singularClass}}Auth\LoginController@logout');
//{{singularClass}} Register
Route::get('/register', '{{singularClass}}Auth\RegisterController@showRegistrationForm');
Route::post('/register', '{{singularClass}}Auth\RegisterController@register');
//{{singularClass}} Passwords
Route::post('/password/email', '{{singularClass}}Auth\ForgotPasswordController@sendResetLinkEmail');
Route::post('/password/reset', '{{singularClass}}Auth\ResetPasswordController@reset');
Route::get('/password/reset', '{{singularClass}}Auth\ForgotPasswordController@showLinkRequestForm');
Route::get('/password/reset/{token}', '{{singularClass}}Auth\ResetPasswordController@showResetForm');
});
I want to set my redirect after logging in and logging out to route with dynamic param. Something like
public $redirectTo = '/cms-name/en/home';
This one above works fine but I need that "en" to be dynamic. How can I achieve that?
Thanks a lot!
Hello @Hesto i installed your package into a new project all's fine, good job. i'm new and just started job with L5.3
that looks like a support request:
i want to now with multi-auth how use roles and permissions in the right way (AUTHENTICATION access)? For example i want that a someone who is registered can't have access level to the admin dashboard... as much as i marked him as admin.
I used hesto package last night and when I login with laravel make:auth package as user ,after closing the browser I am logged out.
when I logged in as admin, even when I closed the browser admin is logged in yet!!
how can I set time out for admin to be logged in? and at least how to consider admin logout when he closed browser?
than you for the package.
How can i change email field to something else for login.
I found a routing issue.
e.g. http://domain.app:8016/admin/home (not login yet) -> http://domain.app:8016/login
The correct redirecting url is /admin/login , not /login.
I modify the following code. It can redirect correct url and fix auth.blade.php.
app/Providers/RouteServiceProvider.php
protected function mapAdminRoutes()
{
Route::group([
- 'middleware' => ['web', 'admin', 'auth:admin'],
+ 'middleware' => ['web', 'admin'],
'prefix' => 'admin',
'as' => 'admin.',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/admin.php');
});
}
resources/views/admin/layout/auth.blade.php
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
- @if (Auth::guest())
+ @if (Auth::guard('admin')->guest())
<li><a href="{{ url('/admin/login') }}">Login</a></li>
<li><a href="{{ url('/admin/register') }}">Register</a></li>
@else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
- {{ Auth::user()->name }} <span class="caret"></span>
+ {{ Auth::guard('admin')->user()->name }} <span class="caret"></span>
</a>
I hope this is useful.
whenever i create a new route in a guard route, when i call the route name from my controller, it throws errror saying the route name is undefined
Route [nameOfRoute] not defined.
Please assist me to solve this issue
How do i get the logged in user in the multi auth i just created like i'll check the number user with (Auth::check())
how to display specific form errors using message bag for multi auth .I have modals and the error are been displayed in all modal forms.
Where can i add witherrors method.
Auth::user()->id error
auth me "admin" and "superadmin" 2auth check get id Admin::admin()->id ???
Guards use same session. Please do something or suggest me way how to fix this. [L5.3]
I am trying to use Socialite (facebook login in particular). Based on the setup instructions and any tutorials I have found, I get the following error:
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of Laravel\Socialite\Two\User given, called in xxxxx/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 294 and defined
Is it possible, the two can work togeather?
How do I check if the user is logged in inside my view that is being used on "/" route? I can only do it on /{guard}/home
hi
thank you for the package.
I have users and admin in my project, in admin page how can I find is this admin or ordinary user?
thanks a lot.
Hello @Hesto In addition to set Multi-auth, how to provide a way to authorize user (Admin or Employee) actions against a given resource?
Laravel's default Authorization approach does it in a simple way.
i tried to implement multiple authentication on my laravel 5.3 project. i used sub-domain routing for each authentication but when i tried to login it gives tokenmismatch exception . i added csrf field and still not woking
i created a fresh laravel 5.3 install and it worked. what i m missing
I have a question and it's, why do you say that only use these package for local development and not production? and what should I do if I want to use it for production? what would happen if I do? does it make my application less secure?
[BadMethodCallException] Method mapAdminRoutes does not exist. when i ran php artisan migrate
i think you miss mapAdminRoutes in RouteServiceProvider
protected function mapAdminRoutes()
{
Route::group([
'middleware' => ['admin', 'web'],
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/admin.php');
});
}
This package uses same database table (password_resets) for each guard.
But there is problem using this -
Lets take an example :
There are two types of users
An admin can be a customer and a customer can be an admin. Same person have two different account but with same email address.
Now when that admin user make any password reset request, application will overwrite any existing (this can be himself as customer) request for same email address. This way the tokens gets lost and email link becomes invalid.
The possible solution is to use a separate table for each user type -
admin_password_resets
table<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAdminPasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token')->index();
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_password_resets');
}
}
app/config/auth.php
file'passwords' => [
'admins' => [
'provider' => 'admins',
'table' => 'admin_password_resets',
'expire' => 60,
],
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
Hi
Route::group([ 'middleware' => ['web', 'admin', 'auth:admin'], 'prefix' => 'admin', 'as' => 'admin.', 'namespace' => $this->namespace, ], function ($router) { require base_path('routes/admin.php'); });
redirect /login when access admin/home if not login
if I remove 'auth:admin', it redirect /admin/login that I want but
`$users[] = Auth::user();
$users[] = Auth::guard()->user();
return null
why that?? and how to fix it.
Thanks
Hi.
Logout method doesn't work in laravel 5.3. I solved it by changing post method to get method in routes.
Also, I had a problem when I removed public folder from my project. Multi-auth routes don't work.
The /{guard}/logout is set to a post request and therefore a get request will not work. I've added a get request to the routes:
Route::get('admin/logout', 'AdminAuth\LoginController@logout');
Could it be a good idea to add this as an additional default route when a new guard is created?
Is there any quick way to set different admin route but keeping admin guard?
php artisan multi-auth:install admin -f
but instead of my-website.com/admin/login
I want to use my-website.com/cms-name/login
I did a clean installation of Laravel 5.3 and followed the steps but when testing the registry this redirect to the same page without showing or errors.
The same happens when you do not put content.
@Hesto Thank you for a useful package!
Correct me if I am wrong, but the stubs need to have {{namespace}} instead of the default App\ being hard-coded? Just realized this after having to refactor things, since the package wasn't working for me.
Also, noticed that the --domain flag in the artisan command is missing or deprecated.
Thanks again, and keep up the good work!
Looks like this package doesn't support multi-auth using Passport. I'm using Passport for the User API authentication but I'm unable to use it for Admin API authentication at the same time created using this package.
I am having a UserAuth controller,
and i have added the Middleware to the route
Route::get('/', function () {
return view('welcome');
})->middleware('user');
but when i try this after loggin in it should come back to home page instead of user/home,
how to change this i have changed this line in middleware RedirectIfUser
public function handle($request, Closure $next, $guard = 'user')
{
if (Auth::guard($guard)->check()) {
//return redirect('user/home');
return redirect()->intended('user/home');
}
return $next($request);
}
but no effect
the only where it's working is by changing in UserAuth/LoginController
public $redirectTo = '/user/home';
to public $redirectTo = '/';
but i dont want as i may have to add this middleware to multiple routes and after logging in it should remain on the protected routes and not go to the user/home..
Followed setup instructions using php artisan multi-auth:install employeer -f
(yes, I realize I spelled "employer" wrong, too tired). After everything is created, the following error appears:
[BadMethodCallException]
Method mapEmployeerRoutes does not exist.
RouteServiceProvider.php
has this added, but the method is not in the class:
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapEmployeerRoutes(); // method not found
//
}
I created the missing method as so:
protected function mapEmployeerRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/employeer.php');
});
}
This allows me to access /employeer/login
, etc., and everything there works. But the employeer/home
route returns a 404 error and is not listed when running php artisan route:list
. What am I missing??
Laravel 5.3
I have two db for example
DB1 is default for all user
DB2 for admin so i made two different connection first one MySql and second one is MySql2
when i changed admin model connection i takes default connection and throw an error that table not exist,
here is my connection code in model i am using laravel 5.3
protected $connection = 'mysql2';
so i am wrong or there is bug
Hi, in my template.blade.php I have the following code in the top of the page:
@if (Auth::guard("doctor")->user())
Welcome, {{ Auth::guard("doctor")->user()->name }}
<a href="{{ url('/doctor/logout') }}">Logout</a>
@endif
Right after registering or logging in, it show the welcome message, but when the user go to any other page the session is lost... I'm using the default login system provided by multi-auth... Any way to keep it logged in?
Hi, Could You add to note information about what is need n=in model in case of using --model option.
I had model previously generated with artisan.
Hello,
I tried to use this package, but i run into a problem. After this:
php artisan multi-auth:install admin -f
Evertything looks fine, but when i try to reach /admin/home without active session, i got redirected to /login, instead of /admin/login.
Hi, I have followed all instructions and able to access the views, however when submitting registration (validation works fine) I am redirected back to the registration page and data not written to the relevant table (so table in my case vendors table is empty). No errors are thrown.
Anything I can try to debug?
Have no idea about what lucid
option is. Could some one explain or give me some ref links to learn more about it ? ๐
Hey Piotr,
Thanks for the plugin - saved me so much time!.
So I see:
$users[] = Auth::user();
$users[] = Auth::guard()->user();
$users[] = Auth::guard('admin')->user();
On routes/admin.php all give a "Admin" object, even though default guard is "web", which should give "User" object.
When I specify the guard as "web" it shows a "User" object.
Is that a bug, or something one should watch out for?
Thanks in Advance.
Hi i have a question,
How do you remove the register from auth, because i don't want someone register from the site.
This is for admin, so another admin being created by super admin.
Thanks.
Need a little help to change the parameters in authentication.
Example :-
By default package gives an authentication with email and password. Instead i wan't to use a local Identity no and password.
Can we use it with Laravel 5.3 API Authentication (Passport) ?
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "multi-auth" namespace.
The package is great! I Love it.
my route in admin.php
like this
Route::resource('amenities', 'AmenityController');
when I try in view: {!! route('amenities.show', [$amenity->id]) !!}
its error
ErrorException in UrlGenerator.php line 314: Route [amenities.show] not defined.
So I must add admin
to {!! route('admin.amenities.show', [$amenity->id]) !!}
then it works.
Is there any solutions without add admin
keyword to route?
another solution is, create the route in web.php
& add middleware.
the code like this
Route::group(['prefix' => 'admin', 'middleware' => 'admin'], function () {
Route::resource('amenities', 'AmenitiesController');
});
After install multi-auth in project (step 3) error appears Method mapEmployeeRoutes does not exist.
. Install should add also method to RouteServiceProvider.php
named mapGuardRoutes()
Hi,
When I go to http://cms.dev/admin/home without login it is redirecting me to http://cms.dev/login
Hello,
I think this package is great but I have one problem. I create admin guard and everything work.
After that I run make:auth to use default LoginController for my users but when I login as users and logout after that it logout the admin user as well?
Is that normal behave? Can I separate their sessions so when logout user the admin stays logged in?
Thanks
for help! I'm newer in laravel.
and when i install multi-auth,it says:
reasonpun@vultr:/ebook$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
[RuntimeException]
Could not scan for classes inside "/ebook/vendor/hesto/multi-auth/src/commands" which does not appear to be a file nor a folder
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]...
thank you for helping me~
The scaffolding generated for the {guard} has get request for logout which is actually supposed to be a post request.
Route::get('admin/logout', 'AdminAuth\LoginController@logout');
replace with
Route::post('admin/logout', 'AdminAuth\LoginController@logout');
Thank for your work.
I'm a new to Laravel.
I created employee auth, when I login with "http://multiauthl3.dev/employee/login", employee user redirected to "http://multiauthl3.dev/employee/home" after authenticated success. Then I access "http://multiauthl3.dev/employee/login" again, I must login again with email and password, employee session not exist.
Please help. Thank you.
Hi, i am having 2 issues with the multi-auth.
I have a user and admin login (2 separate login pages).
When i am not logged as an admin and i want to access a page (example : admin/test123)
It redirect me to the user login and i am not sure where to look to correct that. I don't want my admins to fall into the user platform.
When i login as an admin, it sometimes redirect me to the user login too. The login is working fine because if i manually do /admin, i can see the admin index. It only happen the first time i try like something was saved into a cache. I don't know.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.