Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation on endpoint paths starting with / #782

Open
spras opened this issue Jul 1, 2024 · 4 comments
Open

Update documentation on endpoint paths starting with / #782

spras opened this issue Jul 1, 2024 · 4 comments
Assignees
Labels
documentation A change to the documentation p4 Important Issue

Comments

@spras
Copy link

spras commented Jul 1, 2024

Environment

Reproduction

here is my nuxt.config.ts

  auth: {
    baseURL: process.env.CUSTOM_API_URL + "/",
    globalAppMiddleware: {
      isEnabled: true,
    },
    session: {
      enableRefreshPeriodically: false,
      enableRefreshOnWindowFocus: true,
    },
    provider: {
      type: "local",
      token: {
        maxAgeInSeconds: 18000,
        sameSiteAttribute: "strict",
        secureCookieAttribute: true,
      },
      endpoints: {
        getSession: { path: "/api/session", method: "get" },
      },
      pages: {
        login: "/connexion",
      },
    },
  },

Describe the bug

I'm currently testing upgrade from 0.7.2 to 0.8.0-rc

This break my config : local provider and auth.baseURL defined to a custom base url ex : https://example.com/

Login is posted to the nuxt base URL , not to my custom base url

As a workaround I had to redefine all the endpoints and removing the / prefix .

endpoints: { 
       signIn: { path: 'login', method: 'post' },        
       signOut: { path: 'logout', method: 'post' },        
       signUp: { path: 'register', method: 'post' },        
       getSession: { path: 'session', method: 'get' }    
}

Perhaps it has to become the default values ?

It seems to be linked to the modifications for this issue #742 ,
https://github.com/sidebase/nuxt-auth/pull/750/files , joinPathToApiURL function

Additional context

No response

Logs

No response

@spras spras added bug A bug that needs to be resolved pending An issue waiting for triage labels Jul 1, 2024
@phoenix-ru
Copy link
Collaborator

Hi @spras, it looks correct to me that you redefine your endpoints because of the custom base url.
Using / prefix for endpoints always means to use Nuxt's internal routing - this is intended.

This behaviour was mostly inspired by how URL's are resolved in the browser. For example, assuming you are on https://example.com/subpage and you have <a href="/another">, you will be navigated to https://example.com/another.
I wanted to replicate it, but in the context of Nuxt. Our module assumes that URLs starting with / are local to Nuxt, therefore it avoids extra overhead of crossing the domain boundary.

The fact that using { path: 'login' } satisfies your usecase should be considered a bug rather than a desired result. Similar to browser navigation analogy, I would expect the navigation to be same-level (e.g. { path: 'three' } switching from /one/two to /one/three). But since I don't foresee anyone ever wanting same-level navigation, it is how it is.

I would suggest you to use fully-specified URLs in path configs, because your usecase (I assume) involves going away from Nuxt to an external custom URL.

@Ray0907
Copy link

Ray0907 commented Jul 5, 2024

I faced the similar issue. Here is my nuxt.config file. Ensure that the origin ends with a ‘/’. This worked for me.

auth: {
		provider: {
			type: 'authjs',
		},
		origin: '/prefix/',
	},

@spras
Copy link
Author

spras commented Jul 5, 2024

@phoenix-ru your explaination make sense , it'OK for me. I think documentation should be more detailed and explicit on it.

@phoenix-ru
Copy link
Collaborator

Thank you for the feedback @spras, we will adjust the documentation accordingly

@phoenix-ru phoenix-ru changed the title Local provider, baseURL to a custom base URL breaks in 0.8.0-rc Update documentation on endpoint paths starting with / Jul 5, 2024
@phoenix-ru phoenix-ru added p4 Important Issue documentation A change to the documentation and removed bug A bug that needs to be resolved pending An issue waiting for triage labels Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation A change to the documentation p4 Important Issue
Projects
None yet
Development

No branches or pull requests

4 participants