0

I have built my own UserProvider that is authenticating against another database. Everything is working great; I'm able to log in/out etc. I'm down to returning error messages and running into a snag.

Here is what an example of my code looks like:

MyUserProvider.php

...
$auth = json_decode($response, true);  // response from Guzzle to 3rd party auth

if ($auth) {
    if ($auth['errors']) {
            return redirect('login')
                ->withErrors(['auth' => 'Invalid username or password']);
        } else {
            $myUser = $auth['data']['user']; // auth object from 3rd party.
            $user = User::where('id', $myUser['id'])->first();  // find user in local db.
            ...
        }
    }
}

The part I am struggling with is how to handle the redirect. The error I am getting is:

validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Http\RedirectResponse given

Which make sense, I'm returning a redirect, not an authenticatable object (a user). But, I don't have a user -- my username or password was wrong.

How can I redirect the user back and display a flash message telling them what happened?

Thank you for any suggestions!

Damon
  • 4,151
  • 13
  • 52
  • 108
  • why is redirect inside `validateCredentials`? – Smankusors Mar 07 '20 at 17:16
  • That is a great question. It would make sense to do the 3rd party auth, then based on _that_ result run `validateCredentials` against the local db. – Damon Mar 09 '20 at 13:40
  • Is the redirect specific of 3rd party? How about in `validateCredentials`, just return False, and outside of that function, return redirect? – Smankusors Mar 09 '20 at 16:53

0 Answers0