perlplack

How to change Plack Session's name?


I have two applications on the same domain, but they are both creating a plack_session every time the user logs in. It happens because application A overwrites application B's plack session.

It's a complex process to remove one of them and make them use one that is created by a central application, but for now, how can I change one of those 'plack_session' names to something like 'plack_session2' so they don't see each other?

I don't even know if it is possible.

Here is the document for Plack Session, but I can't see anything that can help me here.


Solution

  • As shown in the documentation you link to, the Plack session middleware is enabled with code like this:

    builder {
        enable 'Session',
            state => Plack::Session::State->new;
        $app;
    };
    

    Later in the same document, you'll find the documentation for the new() method:

    new ( %params )

    The %params can include session_key, sid_generator and sid_checker however in both cases a default will be provided for you.

    session_key

    This is the name of the session key, it defaults to 'plack_session'.

    ...

    Putting all this together, I'd guess (and I haven't ever done this) that you can do what you want with code like this:

    builder {
        enable 'Session',
            state => Plack::Session::State->new(
              session_key => 'my_session_key',
            );
        $app;
    };