Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about RegisteredUserViaGithub function. #1

Open
JimNayzium opened this issue Jul 9, 2024 · 1 comment
Open

Question about RegisteredUserViaGithub function. #1

JimNayzium opened this issue Jul 9, 2024 · 1 comment

Comments

@JimNayzium
Copy link

I am confused where the variable $user is being defined in this area of the class:

`
class RegisteredUserViaGithubController extends Controller
{
public function create(): RedirectResponse
{
return Socialite::driver('github')->redirect();
}

public function store(Register $register): RedirectResponse
{
    $githubUser = Socialite::driver('github')->user();

    // If the user is signed in, associate the GitHub
    // token with their account.


   // RIGHT HERE BELOW
    if ($user = Auth::user()) {
        return $this->login($user, $githubUser);
    }

`

My vscode red underlines it, and also, I just can't make it make sense. But I am very new to laravel and to coding in general.

THANKS for the awesome Laracasts!!

@JimNayzium
Copy link
Author

This is what copilot tells me when I explicitly defined $user before the if statement, then simply did if ($user) ...

The error message you're encountering indicates a type mismatch in your login() method argument. The method expects an argument of type App\Models\User, but it's receiving an argument of type Illuminate\Contracts\Auth\Authenticatable instead. This discrepancy can occur when the method is designed to work specifically with your application's User model but is passed a more generic user object that implements the Authenticatable contract.

In Laravel, the Authenticatable contract is implemented by the default User model, and it defines the necessary methods for authentication. However, when type-hinting in your methods, specifying App\Models\User means you expect exactly that class, not just any class that implements Authenticatable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant