Home

Issue: 2483

Token and auth in own DTO (axios based)

[issue link]

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.

This question is available on Nuxt.js community (#c2157)