How to use multiple authentications with cookie storage?

netteman
Member | 126
+
0
-

The setNamespace() method for multiple authentications
https://doc.nette.org/…thentication#…

is missing in the cookie storage
https://api.nette.org/…Storage.html

Is this a bug or an intention?

(it is in the session storage https://api.nette.org/…Storage.html)

David Grudl
Nette Core | 8228
+
+1
-

You set different cookie name using setCookieParameters()

ijurij
Member | 2
+
0
-

A very simple bike.
You can only rely on the paths in the URL.
Please note that php may receive url after processing by another service on the server (apache, nginx) eg.
For example in url words “backend” and “frontend” are used.
In Bootstrap.php after other $configurator->addConfig(xxx):

        if (validation($url) && (bool) \mb_stristr($url, 'backend')) {
            $configurator->addConfig($rootDir.'/config/auth_backend.neon');
        } else {
            $configurator->addConfig($rootDir.'/config/auth_frontend.neon');
        }

In auth_backend.neon:

security:
    authentication:
        cookieName: backendId

constants:
    TABLE: 'backend_user'

Constant for use in model (UserFacade eg) if you need different tables for users and clients.
This way you don't have to write your own implementation of class User, but use Nette\Security\User class as is.

Last edited by ijurij (2024-11-16 20:14)