How to setup session in glue storefront api?
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:
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
Comments
-
Let me rephrase the question.
In the old Glue there is the possibility to definegetControllerBeforeActionPlugins
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?
0 -
Sorry for being not fast as you might've expected.
I provide here explanation, how I'd implement similar logic.
Adding a plugin into \Spryker\Glue\GlueApplication\GlueApplicationDependencyProvider::getRequestBuilderPlugins let's you enrich the GlueRequest with any details about the request, including details about logged in user/customer.
Session usage is discouraged, since it's kept for a backward compatibility reasons, and as every global resource is a code-smell for a session-less API request processing.
5 -
Hey Andrey! No worries, that was really fast enough ;)
Thank you for your explanation! I will try it that way!
0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,075 ⚖️ - 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
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 75 Spryker News
- 920 Developer Corner
- 780 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 25 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random