nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 924 forks source link

How to change base url #1576

Closed LucianMihalache closed 2 years ago

LucianMihalache commented 2 years ago

Hello, I have multiple api's and have the axios's baseUrl set to an api But I have the authentication api on a different domain I have tried passing baseUrl config when calling loginWith

this.nuxt.$auth.loginWith('apiLogin', {
      data: {
        username: username,
        password: password,
      },
      baseUrl: this.auth_api_url,
      withCredentials: true
    })

But it does not seem that its working. The apiLogin schema extends the LocalSchema and I overwrite just the updateTokens method (because I have multiple tokens)

So, my question is, how can I change the baseUrl for this axios instance, without changing the main axios configuration.

I have tried ovewriting the Auth class in the constructor, but it does not seem to work either

export default class ApiLogin extends LocalScheme {

  constructor($auth, options, ...defaults) {
    $auth.ctx.$axios = $auth.ctx.$axios.create({
      withCredentials: true,
      baseURL: $auth.options.baseURL
    })
    super($auth, options, ...defaults);
  }
}

$auth.options.baseURL is set up in nuxt.config.js

  auth: {
     baseURL: process.env.AUTH_API_URL,
  }
Intevel commented 2 years ago

Currently there is no way to do this, the Auth module accesses the Axios Instance and does not use its own, the only way is to change the Axios configuration, nothing else comes to my mind.