sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.27k stars 163 forks source link

custom baseURL is not working #802

Closed mtzrmzia closed 3 months ago

mtzrmzia commented 3 months ago

Environment

Reproduction

I set the following config:

  auth: {
    provider: {
      baseURL: 'https://tx8_api.test/',
      type: 'refresh',
      endpoints: {
        signIn: { path: 'login', method: 'post' },
        signOut: { path: 'logout', method: 'post' },
        signUp: false,
        getSession: { path: 'me', method: 'get' },
        refresh: { path: 'refresh', method: 'post' },
      },
      token: {
        signInResponseTokenPointer: 'data/access_token',
        cookieName: 'access_token',
        type: 'Bearer',
        maxAgeInSeconds: 60 * 60,
        sameSiteAttribute: 'strict',
      },
      refreshToken: {
        signInResponseRefreshTokenPointer: 'data/access_token',
        cookieName: 'access_token',
        refreshRequestTokenPointer: 'access_token',
        maxAgeInSeconds: 20160 * 60,
      },
      pages: {
        login: '/login',
      },
    },
  },

My backend is running in Valet (Laravel app) exposed in https://tx8_api.test/api and my Nuxt app is exposed in port 3000

Describe the bug

When I try to login, happens this Screenshot 2024-07-13@2x The baseURL still the default one. On Postman the request is successfully Screenshot 2024-07-13@2x

Additional context

I'm following the steps to use an external backend but doesn't work for me

No response

Logs

No response

zoey-kaiser commented 3 months ago

Hi @alfredomtzrmz 👋

You have a slight misconfiguration inside your nuxt.config.ts. The baseURL should be in the root auth property and not inside the provider!

  auth: {
+  baseURL: 'https://tx8_api.test/',
    provider: {
-    baseURL: 'https://tx8_api.test/',
      type: 'refresh',
    },
  },

I did see, that inside the one example for external backends, we forgot to wrap the endpoints in the provider object, I will quickly fix this in the docs 😊


I also created a small reproduction of this and setting the baseURL correctly, properly resolves the external URL! See here: https://github.com/zoey-kaiser/nuxt-auth-reproductions/tree/802-external-base-url

Screenshot 2024-07-15 at 16 53 23

mtzrmzia commented 3 months ago

@zoey-kaiser Thanks! But now i got this error net::ERR_CERT_COMMON_NAME_INVALID and my config:

  auth: {
    baseURL: 'https://tx8_api.test/api/auth/',
    provider: {
      type: 'refresh',
      endpoints: {
        signIn: { path: 'login', method: 'post' },
        signOut: { path: 'logout', method: 'post' },
        signUp: false,
        getSession: { path: 'me', method: 'get' },
        refresh: { path: 'refresh', method: 'post' },
      },
      token: {
        signInResponseTokenPointer: 'data/access_token',
        cookieName: 'access_token',
        type: 'Bearer',
        maxAgeInSeconds: 60 * 60,
        sameSiteAttribute: 'strict',
      },
      refreshOnlyToken: false,
      refreshToken: {
        signInResponseRefreshTokenPointer: 'data/access_token',
        cookieName: 'access_token',
        refreshRequestTokenPointer: 'access_token',
        maxAgeInSeconds: 20160 * 60,
      },
      pages: {
        login: '/login',
      },
    },
  },
mtzrmzia commented 3 months ago

@zoey-kaiser nevermind, I forgot to set my virtual domain to secure 😅. Now works fine!