-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
RFC: Improve the handing of baseURL
to be more intuitive
#797
Comments
Hello Zoey, thank you for opening this RFC! I think an important improvement for this is to ensure that an absolute URL is used as-is and does not attempt to prepend the This method performs the edge-case handling for:
This could be implemented by replacing nuxt-auth/src/runtime/utils/url.ts Line 17 in 3b5cc43
This would have the added benefit that someone could use different servers for each endpoint in their configuration, in an extreme edge use-case. For example: endpoints: {
signIn: {path: 'https://auth-server/login'},
getSession: { path: 'https://session-server/session' },
} We would want to consider how this change may break existing configurations, but I think it would provide a much more intuitive behavior. Pending further discussion and ideas, I'm happy to contribute a PR for this. |
I made a quick demo to test out serval options of a
The best solution I came up with was to use function joinMethodTwo(base: string, path: string) {
return withBase(path, base)
} |
Referring to issue #840, I believe the URL should not be automatically formatted by the library. Instead, the library should validate the URL and return an error if it's invalid—or at the very least, log a warning. Currently, no error is reported, making debugging quite challenging. To address this, I propose the following approach: function formatUrl (base: string = ‘’, path: string) {
let host = base
if (!base) {
host = location.origin
}
try {
const url = new URL(path, host) // will throw an error if it can’t form a proper URL
return url.href
} catch (err) {
// return the error or handle it
}
} One potential drawback of this approach is that if the user passes another URL as the endpoint’s path (e.g., https://example.com/donde/), the base URL won't be applied. However, I don't see this as a significant issue. In some cases, the user might intentionally want to call a different URL for a specific endpoint. |
Describe the feature
The current logic used to determine if the
auth.baseURL
is internal or external is misleading and hard to understand. The main issue is that the module needs external URLs to be configured in a very specific way to properly identify it as an external URL.Examples taken from #782 by @coreyshuman:
Example 1 - Incorrect URL
Example 2 - Incorrect URL
Example 3 - Incorrect URL
Example 4 - Correct URL
In #796 we updated the docs to better explain this behaviour, however we should look into improving this, to make it less complex.
How would you implement this?
Some potential ways to better determine if a URL is internal or external:
schema
(https
orhttp
) to signify a URL is external/
inside thebaseURL
andendpoints
and then composing and adding them as needed, to better infer the URLs, instead of just combining themMore suggestions are welcome!
Additional information
Provider
The text was updated successfully, but these errors were encountered: