Comments (10)
Is your ApplicationServiceProvider
being added after the Sentinel service provider?
I did a quick test and the hasher i set seems to be set properly before and after i try to log a user in via login
or authenticate
methods.
from sentinel.
Yes, my service provider is after the SentinelServiceProvider:
'providers' => array(
// ...
/*
* Additional providers
*/
'Cartalyst\Sentinel\Laravel\SentinelServiceProvider',
'Barryvdh\Debugbar\ServiceProvider',
/*
* Application Service Providers
*/
'Appp\Providers\AppServiceProvider', //<-- that one
),
My boot method currently looks like this (using dd to check if it reaches that code):
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Sentinel::setHasher(new CallbackHasher(
function($value)
{
return Hash::make($value);
},
function($value, $hashedValue)
{
dd([$value, $hashedValue]);
}
));
}
from sentinel.
Seems to be working fine here using your exact same setup, and it does dump on authenticate
from sentinel.
This is my controller's method code; maybe I am doing something wrong here even:
public function postLogin(Request $request)
{
$credentials = $request->only('email', 'password');
try {
// Authenticate with our credentials, if it succeeds continue to the home screen
if (Sentinel::authenticate($credentials, $request->has('remember'))) {
return redirect()->intended(route('home'));
}
} catch(NotActivatedException $ex) {
return redirect('/auth/activate');
}
// ... otherwise return to the login page
return redirect('/auth/login')
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => 'Invalid credentials / No user found',
]);
}
I am also wondering why the system would let me log in with an email, but not with a username. I already changed the User
s $loginNames
to ['email', 'username'];
. Very strange…
from sentinel.
Copied that over and defined the route and it's working as well.
from sentinel.
Okay, so I did some more testing and it seems like the closure for the "sentinel.hasher" in the SentinelServiceProvider gets definitely called before my Sentinel::setHasher()
method. But when I do a dd in my controller method it somehow was set to the NativeHasher once again.
I just tried to move the setHasher method to my register() function in the ServiceProvider and that time the Sentinel one was called after my custom one (I haven't changed the order of my providers).
Digging further I found out that the SentinelBootstrapper gets executed after my service provider, and creates a sentinel instance with the default hasher.
Is there a way to work around this? It really is weird that it seems to work on the setup everyone else but mine.
from sentinel.
@spaceemotion are you using the correct alias?
from sentinel.
The SentinelBootstrapper is only triggered by the Native facade, apparently that is being used on your application which is wrong.
Laravel applications should be using the Laravel facade, Cartalyst\Sentinel\Laravel\Facades\Sentinel
from sentinel.
Oh crap, didn't think about that. Yes I indeed used the 'Native' one, well - thanks for the hint!
That still doesn't fix the username issue. Logging in through an email works, but when using a username the system still gives off an error (as explained above). I checked the query object that gets executed and it seems like Sentinel tries to get an email with the given username. Is there a way to decide which field to use on which occasion (if the name contains '@', then use 'email', otherwise 'username')?
from sentinel.
You can pass in login
instead of explicitly stating email or username, that will work for both fields if they're defined on the loginNames array.
from sentinel.
Related Issues (20)
- Using Sentinel statelessly without starting session HOT 3
- Prevent Users from getting same Sesstion ID
- i cant use middleware auth or guest inside of my routes HOT 3
- Is there a way to add users via the cli with their rolls etc ? HOT 2
- [Proposal] Incomplete installation guide - Add hint to install database schema HOT 1
- How do I get Sentinel to authenticate checking additional fields? HOT 2
- HasAccess function return false if a user have multiple roles and different permission HOT 8
- Prefix in database tables
- PostgreSQL ERROR: operator does not exist: boolean = integer HOT 3
- registerAndActivate on a different connection doesn't work with config() HOT 5
- Cartalyst\Sentinel\Users\EloquentUser::getUserId(): Return value must be of type int, null returned
- illuminate/ packages older version HOT 1
- Activation::complete method returns PHP Fatal error: Uncaught RuntimeException: A facade root has not been set error
- Support for Laravel 9.6 and PHP 8.* HOT 2
- Authenticate using username or email
- unable to login HOT 2
- Laravel 10 Support HOT 4
- Deprecation warnings HOT 1
- Question: does it support user impersonation?
- support laravel 11 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentinel.