A
Alokai•17mo ago
jbialon

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
skirianov
skirianov•17mo ago
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?
jbialon
jbialonOP•17mo ago
yes, i looked there, but can't find where token returned from magento is set on context/cookie
skirianov
skirianov•17mo ago
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.
skirianov
skirianov•17mo ago
have you seen this one? It's old implementation, but maybe will help
jbialon
jbialonOP•17mo ago
Yes, but cant find where state.setCustomerToken() is called
skirianov
skirianov•17mo ago
Ah okay got, here’s the reply from one of our engineers
skirianov
skirianov•17mo ago
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
Want results from more Discord servers?
Add your server