api client context in frontend app
Hi guys,
I'm trying to build new integration using new Sdk Integration Boilerplate and I got stuck on how to get api-client context on frontend nuxt app. What I want to do is, to add token that i get from api-client/middleware response, after I get it on frontend app I want to save the token in app context so that api-client can take it and adds that Bearer token to header on every call. I have tried to add new fields to: packages/api-client/src/types/context/index.ts and read them here: playground/app/pages/methods/exampleMethod.vue but with no success. Maybe Its wrong idea to handle authentication token on frontend app, and it should only be handled on api-client?
7 Replies
Hey there 👋
Good question 😊 I asked our engineers to take a look at it and meanwhile, have you checked Magento 2 SDK integration for inspiration?
yes, i looked there, but can't find where token returned from magento is set on context/cookie
GitHub
magento2/packages/api-client/src/index.server.ts at main · vuestore...
Vue Storefront 2 integration for Magento 2. Contribute to vuestorefront/magento2 development by creating an account on GitHub.
have you seen this one? It's old implementation, but maybe will help
Yes, but cant find where state.setCustomerToken() is called
Ah okay got, here’s the reply from one of our engineers
I at first didn’t get the question right. Access token is stored in the middleware only and since middleware is a separate application it can’t simply share it to the client.
But you can do as per screenshot
![No description](https://cdn.answeroverflow.com/1143829846225592320/IMG_4580.png)