How to get url of the domain from the http action?
I am trying to redirect the user to frontend after I have done some validation on http action and I am using this util function to getURL
and In my http action I am doing this :
But its throwing error :
7 Replies
Wanted to ask is my approach correct or we can do it in other better way
@Abhishek hey there. yep, because the http action runs on the server, not in the browser environment, it doesn't know what the app's current URL is
so you'd need to return some error code and then have the app handle the error and do this re-routing app-side
@jamwt to use .env variable for localhost, production domain right?
so, what's calling this http action? the browser? and it is using fetch?
sorry, I need a little more background to be helpful
Sure @jamwt so here is repo - https://github.com/imaxisXD/AIvy-Post/blob/main/convex/oauth.ts
so this is called by the LinkedIn service as a redirect URL to get the state and code and then call the LinkedIn API with the received code from the previous step.
GitHub
AIvy-Post/convex/oauth.ts at main · imaxisXD/AIvy-Post
Contribute to imaxisXD/AIvy-Post development by creating an account on GitHub.
This might help:
- if the redirect is to your website’s url, you’ll need to handle that either in the browser (for a static site eg) or in the server serving your website dynamically (eg the nextjs route). From there you read the state & code from your the window’s location / request url. You can then call convex with those as a parameter.
If you set the convex backend as the redirect, eg with the …convex.site/myendpoint syntax, then your backend no longer knows what frontend initiated this request. So you could set an environment variable on your convex deployment that has the website url to redirect to after the code exchange.
The trick is in this case the frontend needs to pass the redirect url of the convex.site url and the backend needs to know the frontend. In your oauth provider you’d be configuring the convex url as the redirect. Make sense?
Totally makes sense, I will go with a convex backend as the redirect approach
Thanks @ian