CodeIgniter Forums
myth-auth How not to load the default routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: myth-auth How not to load the default routes (/thread-79398.html)

Pages: 1 2


myth-auth How not to load the default routes - rafinhaa - 06-09-2021

Hi everyone, I am using myth for authentication in a study application. In the file "vendor\myth\auth\src\Config\Routes.php" 

PHP Code:
<?php

/*
 * Myth:Auth routes file.
 */
$routes->group('', ['namespace' => 'Myth\Auth\Controllers'], function ($routes) {
    // Login/out
    $routes->get('login''AuthController::login', ['as' => 'login']);
    $routes->post('login''AuthController::attemptLogin');
    $routes->get('logout''AuthController::logout');

    // Registration
    $routes->get('register''AuthController::register', ['as' => 'register']);
    $routes->post('register''AuthController::attemptRegister');

    // Activation
    $routes->get('activate-account''AuthController::activateAccount', ['as' => 'activate-account']);
    $routes->get('resend-activate-account''AuthController::resendActivateAccount', ['as' => 'resend-activate-account']);

    // Forgot/Resets
    $routes->get('forgot''AuthController::forgotPassword', ['as' => 'forgot']);
    $routes->post('forgot''AuthController::attemptForgot');
    $routes->get('reset-password''AuthController::resetPassword', ['as' => 'reset-password']);
    $routes->post('reset-password''AuthController::attemptReset');
}); 


I just wanted to use the login route, however if I make changes to this file in a future change my changes would be overwritten.

Any way to do this?

Thank you all!


RE: myth-auth How not to load the default routes - ikesela - 06-09-2021

auth:publish ( -> php spark auth:publish ), edit the publish file, dont edit source, after publish, file will be copied to VIEW/Auth , for the route u need to remove namespace , since all file in main view


RE: myth-auth How not to load the default routes - paliz - 06-09-2021

Comment routes you dont need

/* like thst*/


RE: myth-auth How not to load the default routes - rafinhaa - 06-10-2021

(06-09-2021, 10:41 PM)paliz Wrote: Comment routes you dont  need

/* like thst*/
That way in a future update the file will be rewritten and my changes erased







(06-09-2021, 04:38 PM)ikesela Wrote: auth:publish ( -> php spark auth:publish ), edit the publish file, dont edit source, after publish, file will be copied to VIEW/Auth , for the route u need to remove namespace , since all file in main view


I only published the auth config edited the $views variable to:



PHP Code:
public $views = [
 
'login' => 'App\Views\layouts\login',
 ]; 

when url access gives an exception:

[Image: Screenshot-1.png]

My route file:

PHP Code:
$routes->group('/', ['filter' => 'login'], function($routes){
 
$routes->get('''CDR\Dashboard::index');
 
$routes->group('users', function($routes){
 
$routes->get('add''CDR\Users::add');
 });
}); 

edit
I don't think I understand very well, do I need to remove the myth-auth namespace?


RE: myth-auth How not to load the default routes - paliz - 06-11-2021

yes you need it

$routes->group('', ['namespace' => 'Myth\Auth\Controllers'], function ($routes) {
}


RE: myth-auth How not to load the default routes - rafinhaa - 06-11-2021

(06-11-2021, 10:17 AM)paliz Wrote: yes you need it

$routes->group('', ['namespace' => 'Myth\Auth\Controllers'], function ($routes) {
}
If I use namespace my controllers is not found

PHP Code:
$routes->group('/', ['namespace' => 'Myth\Auth\Controllers'], function($routes){
 
$routes->get('''CDR\Dashboard::index');
 
$routes->group('users', function($routes){
 
$routes->get('add''CDR\Users::add');
 
$routes->post('add''CDR\Users::store');
 });
}); 



404 Not Found
Controller or its method was not found: \Myth\Auth\Controllers\CDR\ Dashboard :: index

is there any way to do it?


RE: myth-auth How not to load the default routes - paliz - 06-11-2021

Put dashbord ctl in app/conttoller


RE: myth-auth How not to load the default routes - rafinhaa - 06-14-2021

(06-11-2021, 07:46 PM)paliz Wrote: Put dashbord ctl in app/conttoller

I tried different ways, followed your tips, but to no avail.

I had to do it this way:
PHP Code:
$routes->group('/', ['filter' => 'login'], function($routes){
 
/** Redirect attempts to Registration, Activation and Forgot/Resets */
 
$routes->match(['get''post'], 'register''CDR\Dashboard::index');
 
$routes->get('activate-account''CDR\Dashboard::index');
 
$routes->get('resend-activate-accoun''CDR\Dashboard::index');
 
$routes->match(['get''post'], 'forgot''CDR\Dashboard::index');
 
$routes->match(['get''post'], 'reset-password''CDR\Dashboard::index');
 
/** Redirect end */
 
$routes->get('''CDR\Dashboard::index');
 
$routes->group('users', function($routes){
 
$routes->get('add''CDR\Users::add');
 
$routes->post('add''CDR\Users::store');
 });
}); 



RE: myth-auth How not to load the default routes - ikesela - 06-14-2021

after publish, system will copy firl AuthController to controller folder. myth auth config/routes.php , remove the name space for route. it will load from main view folder : View/Auth


RE: myth-auth How not to load the default routes - rafinhaa - 06-14-2021

(06-14-2021, 12:17 PM)ikesela Wrote: after publish, system will copy firl AuthController to controller folder. myth auth  config/routes.php , remove the name space for route. it will load from main view folder : View/Auth

That doesn't work either, keep using myth-auth/src/Config/Routes.php