The ability to use different baseURLs on client and server
Describe the feature
I'm not 100% sure if this is a 'new' feature, but I couldn't figure out a way to do it. I need to use different baseURLs for fetching the user endpoint on the server and the client. For example, I need to fetch it on the server using this URL:
http://172.30.30.2/api/user/
and using this one on the client:
https://somepublicdomain.com/api/user/
How would you implement this?
It could be done via specifying different envKey variables for client and server or by using different runtimeConfig variables.
Additional information
- [x] Would you be willing to help implement this feature?
Provider
- [ ] AuthJS
- [x] Local
- [ ] Refresh
- [ ] New Provider
I am not sure we can support this right now. You can already set AUTH_ORIGIN environment variable in runtime, but how do you "set" it for a client build? At the moment all the configuration is explicitly transferred from server to client using
https://github.com/sidebase/nuxt-auth/blob/8dc77e58ef024d87edf2f42a45a03eafa481ff15/src/runtime/plugin.ts#L20-L24
I think you can better resolve this by using the equivalent of hosts configuration in your DNS.
but how do you "set" it for a client build?
Theoretically, we could have two env variables like AUTH_ORIGIN and SERVER_AUTH_ORIGIN and the first one could be exposed to the client and the second one could be used only on server side. The same idea could work with runtimeConfig variables like this:
runtimeConfig: {
apiBaseUrl: 'http://172.30.30.2/api',
public: {
apiBaseUrl: 'https://somepublicdomain.com/api',
},
},
I think you can better resolve this by using the equivalent of
hostsconfiguration in your DNS.
I first thought of this but it wouldn't work because they have different protocols (http & https). I mean I could handle the name resolution but the protocol is still different.
@sadeghi-aa I am sorry, but I think it is a super niche usecase and I don't think I can help you here. You can always fork the library and add it in yourself. I will be up to looking into your implementation inside a PR, but I wouldn't guarantee that it gets merged (depends on the complexity of the change).
@phoenix-ru
Yeah, I understand your point here. I might work on it sometime. Currently I've commented the exact lines you mentioned using the patch-package package and it's behaving the way I need it to. This way the server uses the variable in the env and doesn't change the baseURL config for the client side which I've already set to my 'public' address. The env variable is also not exposed to the client with this method.
https://github.com/sidebase/nuxt-auth/blob/8dc77e58ef024d87edf2f42a45a03eafa481ff15/src/runtime/plugin.ts#L20-L24