|
Hello! I'm try force user change password after login with magiclink. in Auth.php public function loginRedirect(): string
{
if (session('magicLogin')) {
return redirect()->route('set_password');
}
but cause error Config\Auth::loginRedirect(): Return value must be of type string, CodeIgniter\HTTP\RedirectResponse returned |
Replies: 2 comments 3 replies
|
|
Hi @caosdp-rs, public function loginRedirect(): string
{
if (session('magicLogin')) {
$url = setting('Auth.redirects')['set_password'];
}else{
$url = setting('Auth.redirects')['login'];
}
return $this->getUrl($url);
}But I saw something in your code that I would like to explain a little. You could write your code more readable and beautiful. public function loginRedirect(): string
{
$url = setting('Auth.redirects')['login'];
if (session('magicLogin')) {
$url = setting('Auth.redirects')['set_password'];
}
return $this->getUrl($url);
}As you can see, both of the above codes work correctly, but which one is better? You may not feel much difference here, but the habit of using Another way could be as follows: public function loginRedirect(): string
{
if (session('magicLogin')) {
return setting('Auth.redirects')['set_password'];
}
$url = setting('Auth.redirects')['login'];
return $this->getUrl($url);
} |
Config\Auth::loginRedirect()must return URL string, not Response object.