Non API/API routes?
Is there a way to have something like API routes even though it's not part of an API. An example of this would be the OpenID connect protocol or OAuth2 protocol for authentication. For example Google calls a callback that needs to be a GET but Apple wants to call a POST and pass me the data in form-data format. Is there a way to just have a GET/POST handler that then redirects to the rest of the website?
Thanks
14 Replies
wise-white•7mo ago
why not use an API route?
correct-apricot•7mo ago
You could do it using a $.ts I guess
Similar to how better auth is handled
correct-apricot•7mo ago
TanStack Start Integration | Better Auth
Integrate Better Auth with TanStack Start.
correct-apricot•7mo ago
And then you write your logic in the handler
quickest-silverOP•7mo ago
Because if you have an actual /api API It seems that with Tanstack Start you have to have an API route under /api and for auth callbacks that's misleading since an auth callback is not part of the public API.
optimistic-gold•7mo ago
How about changing API base path?
You can do so by
server.apiBaseURL
in config.fair-rose•7mo ago
It’s how it’s done on nextjs as well
quickest-silverOP•7mo ago
That would break the actual API at /api
Not sure why you mention this but ok 👍
wise-white•7mo ago
this is only an "aesthetic" issue, right?
while it would work you don't like that the path starts with /api?
would having multiple API directories solve that?
you could also use a nitro rewrite
quickest-silverOP•7mo ago
Yeah. The ideal solution would be to be able to just export a
GET
, POST
, etc. function and let TSS understand that that route is an "api route". But not sure how technically challenging it is.
Anyway, just wanted to make sure that's the only way forward. Thank you all ❤️
It's also an organizational issue. If all routes related to auth are under /auth
then it's kinda weird to have a single callback route be under /api/auth
.wise-white•7mo ago
I doubt we will ever mix API routes and non API routes in a single prefix
did you look at the rewrite solution via nitro route rules?
quickest-silverOP•7mo ago
I'll just have
/api/auth
. It's the most maintainable solution AFAICSoptimistic-gold•7mo ago
Ah, I see. Sorry to bother you.
quickest-silverOP•7mo ago
No worries bro