1

I am starting a new project, which is updating an old website, there is a requirement to move the old user accounts and user data over to the new system, when a user logs into the new site for the first time.

Therefore while I want to use the default Authentication in a Laravel 12 Starter Kit, it needs to be a manual authentication so that if the default system fails to find a match, I can look the user up on the old database in realtime, and start a worker to move the users data over and create a new account. That is all fine, but I am struggling to understand how to call the new authenticate function.

I have followed the authentication page (Laravel Docs) for manually authenticating users, thats fine, but I am struggling to understand how to correctly call it from the rest of the starter package.

Within App\Http\Controllers\Auth\AuthenticatedSessionController.php there is this function

    public function store(LoginRequest $request): RedirectResponse
    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect()->intended(route('dashboard', absolute: false));
    }

Which is called when the Log In button on the login screen is clicked, but I think I need to replace the $request->authenticate(); line with the pointer to my bespoke function to attempt to authenticate the user.

However, if do something like

    #$request->authenticate();
    $bespokeAuth = new LogInController();
    $request = $bespokeAuth->authenticate($request);

while my code is executed, the results are not being returned back to the store function, hence error messages are not returned, and the system no longer moves to the next page on a successful login.

Can anyone tell me what I am missing, or doing wrong please?

10
  • I don't believe you should be calling new LogInController(), that skips dependency injection. Commented Aug 27 at 16:25
  • Yes, to be honest, that was my first thought, that new LogInController() shouldn't be needed, but if thats the case, I am missing something - because I dont see where/how else the 'manual authentication' is called? Commented Aug 27 at 17:47
  • Is it possible to simply migrate your old users to new users in a users table or if you users are in a differnt table set that as the authentication target or as the table for the users model? Commented Aug 27 at 18:00
  • @TobyAllen Unfortunately not, as the passwords are hashed and stored encrypted, so the only way of changing them over is when they log on. It has been suggested that we could force a password change, but the feedback was not in favour of that given the age range and skill set of website users, it was felt it was just opening the door to trouble. Plus they want to ensure the new users table is only currently active users, and after six months, remove all former users and therefore delete out of date info. Commented Aug 27 at 18:21
  • @0ro2 I do find it a bit bizarre that the Laravel docs cover how you can create your own system using the Auth facade, but dont cover anything on implementing it in the system - again unless I am missing something. Commented Aug 27 at 18:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.