Static GitHub Issues

[2483] Token and auth in own DTO (axios based)

prev: dev branch Vue-apollo not working
next: Passed data object becomes Observer for child components, but not page components

Hi,

I write my own DTO (Data Transef Object) based on axios router. I need create an instance of my DTO client and set token per request/user on server and i want use that client on both (client and server).

import { Client } from '@caloriosa/dto'

// I need available request, document and app here (on server-side request and on client-side document)

let client = new Client({
 url: "my.api.url",
 token: req.cookies.token || document.cookies.token
}

app.$client = client;
  • In nuxtServerInit i have a request, it's not triggered on client side ($client not instantiated on client side)
  • In plugins I instantiate it, inject to contex, but it's global. Every request overwrites token for client? Or plugin initialization on server is per request (isolated)?
  • Create $client in create or beforeCreate via mixin? Is request available here?
  • Other solution?

So I have no idea where to create my client instance. I need avaliable $client in application on client and on server per request (because token, user identification).

Thanks.

PS: I can't use auth module or axios module, i written own DTO service and I need use it in my project.

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2157">#c2157</a>)</em></sub></div>