Im just trying to make a new user, log that user in, send a verification email and redirect to the user dashboard where the "you need to verify your user" messages is. It works up until the redirect, where it suddenly fails. In the "auth" middleware it tells me that the user is not logged in for some reason, but it works in the registration controller. This is my registration controller function.
public function store(RegisterUserRequest $request)
{
$user = new User();
$user->name = $request->name;
$user->email = $request->email;
$user->password = bcrypt($request->password);
$user->points = 0;
$user->role_id = UserRole::USER;
$user->verified = $request->verified ?? 0;
$user->verify_email_code = Str::random(30);
$user->save();
$userdata = [
'email' => $request->email,
'password' => $request->password
];
if (Auth::attempt($userdata)) {
//send user to user dashboard
return redirect()->route('users.show');
} else {
// login not successful, send back to form
return redirect()->back()->withErrors(__("messages.innloging-mislykkes"));
}
}
I have tried redirecting to an action, redirecting to the view directly and so on. I suspect the session is not persisting.