How to setup session in glue storefront api?

DavidGreiner
DavidGreiner Spryker Backend-Developer Spryker Solution Partner Posts: 11 🧑🏻‍🚀 - Cadet
edited April 15 in Spryker Development

Hey guys! We are trying to use glue storefront api with customer session access but we are struggling with \Spryker\Glue\GlueStorefrontApiApplication\Application\GlueStorefrontApiApplication::setUpSession

It looks like there is some workaround implemented to use \Spryker\Glue\GlueApplication\Session\Storage\MockArraySessionStorage.

Please compare: https://github.com/spryker/glue-storefront-api-application/blob/master/src/Spryker/Glue/GlueStorefrontApiApplication/Application/GlueStorefrontApiApplication.php

Also the setUpSession method looks like a forgotten workaround because it is not using Spryker conventions to use factory methods to instantiate classes.

/**
 * @return void
 */
protected function setUpSession(): void
{
    (new SessionClient())->setContainer(
        new Session(
            new MockArraySessionStorage(),
),
);
}

Can anyone please explain how this is supposed to be used and adjusted?

@spryker

Tagged:

Comments

  • DavidGreiner
    DavidGreiner Spryker Backend-Developer Spryker Solution Partner Posts: 11 🧑🏻‍🚀 - Cadet

    Let me rephrase the question.
    In the old Glue there is the possibility to define getControllerBeforeActionPlugins in the GlueApplicationDependencyProvider.

    A SetCustomerBeforeActionPlugin is used here to set the customer in the session from the RestRequestTransfer.

    How is this intended for the storefront api? Can someone explain this?

  • DavidGreiner
    DavidGreiner Spryker Backend-Developer Spryker Solution Partner Posts: 11 🧑🏻‍🚀 - Cadet

    Hey Andrey! No worries, that was really fast enough ;)

    Thank you for your explanation! I will try it that way!

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)

    Heyhey @DavidGreiner ,

    We are trying to use glue storefront api with customer session access

    I also want to emphase on the point that Glue (Storefront|Backend) API is a RESTful API and therefore should not be tied to any session! I would avoid it as much as I could!

    What I normally suggest for a hybrid-solution with Yves (and what i implemented in a project partly already):
    When you login through Yves, generate the access-token for glue in the background and provide it (through html?) to the frontend. There is just one case you need to cover additionally: The token can expire and you need to catch this somehow and renew it.

    Hope this helps somehow.

    All the best,

    Florian