I want to login users after authenticating them using OAuth and Google account without entering any password.
I know Auth::login
functon can do such action but I don't know how to get the user instance while they haven't been authenticated yet.
Is there a way to do that?
Manually Logging In A User If you need to log an existing user instance into your application, you may call the login method with the user instance: Auth::login($user); This is equivalent to logging in a user via credentials using the attempt method.
Auth::user() — You can check if a user is authenticated or not via this method from the Auth Facade. It returns true if a user is logged-in and false if a user is not. Check here for more about how Facades work in Laravel.
Guards define how users are authenticated for each request. For example, Laravel ships with a session guard which maintains state using session storage and cookies. Providers define how users are retrieved from your persistent storage.
You can 'manually' log a user in in two diefferent ways:
// log user in by ID
Auth::loginUsingId([id of user]);
Or
$user = User::find([id here]);
// or maybe
$user = User::whereUsername([username here])->first();
// and then
Auth::login($user);
See the documentation for authentication.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With