I get odd bugs in the process of logging using myth-auth. So I have a one page user that can be accessed without logging, and an admin page that requires the user to login if they want to access it. But after logging to the admin page, it redirect to the previous page. So I logged in again, and it can go into the admin page. The weird thing is, when I logged out, the same thing starts all over again.
I start to think there might be something wrong with the App/Config/Route page or the AuthController.
public function login()
{
// No need to show a login form if the user
// is already logged in.
if ($this->auth->check()) {
$redirectURL = session('redirect_url') ?? base_url('admin');
unset($_SESSION['redirect_url']);
return redirect()->to($redirectURL);
}
// Set a return URL if none is specified
$_SESSION['redirect_url'] = session('redirect_url') ?? previous_url() ?? base_url('admin');
return view($this->config->views['login'], ['config' => $this->config]);
}
/**
* Attempts to verify the user's credentials
* through a POST request.
*/
public function attemptLogin()
{
$rules = [
'login' => 'required',
'password' => 'required',
];
if ($this->config->validFields == ['email']) {
$rules['login'] .= '|valid_email';
}
if (!$this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
$login = $this->request->getPost('login');
$password = $this->request->getPost('password');
$remember = (bool)$this->request->getPost('remember');
// Determine credential type
$type = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
// Try to log them in...
if (!$this->auth->attempt([$type => $login, 'password' => $password], $remember)) {
return redirect()->back()->withInput()->with('error', $this->auth->error() ?? lang('Auth.badAttempt'));
}
// Is the user being forced to reset their password?
if ($this->auth->user()->force_pass_reset === true) {
// return redirect()->to(route_to('reset-password') .'?token='. $this->auth->user()->reset_hash)->withCookies();
return redirect()->to(route_to('reset-password') . '?token=' . $this->auth->user()->reset_hash);
}
$redirectURL = session('redirect_url') ?? base_url('admin');
unset($_SESSION['redirect_url']);
// return redirect()->to($redirectURL)->withCookies()->with('message', lang('Auth.loginSuccess'));
return redirect()->to($redirectURL)->with('message', lang('Auth.loginSuccess'));
}
and here the route page
// ROUTE USER
$routes->get('/', 'Page::index');
/* ROUTE PER-PAGE */
$routes->get('/admin', 'Page::admin');
I found the bugs, in the user views I write this code
but if I access the admin page with url, it redirect to index.php/login. So i change
<a href="/login">
to<a href"index.php/login">
. So this is just url issues