Is there a way to display a 404 for any routes not defined in main.wasp?
version: 0.13.2 on MacOS
10 Replies
Hi @wardbox. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, there is a way to handle wildcard routes for 404 or not found redirects in Wasp. You can do this by defining a wildcard route that will catch any routes not specified in your
main.wasp
file. Here is an example:
This wildcard route should probably be the last route in your main.wasp
file to ensure that it only catches routes that have not been defined elsewhere.
Please note that this is a workaround and the Wasp team is planning to provide a more formal solution for this in the future.
Source (https://discord.com/channels/686873244791210014/1112653557934592022)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @wardbox, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Hi @wardbox, the bot is 100% right (finally some help from AI :D)
There's an open issue to provide proper support for this: https://github.com/wasp-lang/wasp/issues/266
But until then, the wildard route is the way to go!
This worked great! Is there anything I need to do to get google/github auth working properly in conjunction with this? Hitting an issue where google auth redirects to /oauth/callback which gets caught by the wildcard.
It does successfully make the user in the DB, just doesn't have a chance to create a session or something and redirects back to login
@miho pls help, auth is your territory
To test I removed the wildcard route - I suspect it's something with the google oauth client. Sometimes I get
Error 400: redirect_uri_mismatch
and sometimes it works, can't really track down a consistent difference between logins. I've got this in my google cloud client http://localhost:3001/auth/google/callback
:think_spin:
could have been delay to updates on the web client, can close this out!
Actually, still get the issue with the wildcard route, sorry for spam 😅@wardbox no worries! So now it works without the wildcard route, but it doesn't with it, correct?
We will let @miho take this one since he knows the most both about Google auth and about wildcard route, he should be seeing this tomorrow.
that's correct
Yeah, so we have a client route that finishes the login part of the OAuth flow, so if that route can't be loaded -> the session won't be created 😦 that's a good explanation on your part!
About the wildcard route, it's important that it's the last route in the React Router list of routes. Bu it can't be because of the way we wrote the templating for the routes.
So ... we can't support wildcard routes + OAuth in the current implementation. We should add proper support for catch all route for error page in Wasp.
Tracking it here: https://github.com/wasp-lang/wasp/issues/2029 it's an easy fix that should come in the next Wasp version
GitHub
User defined routes can override
/oauth/callback
and break OAuth ...Context: https://ptb.discord.com/channels/686873244791210014/1238173111363305574/1239325290824732673 If users define a wildcard route (to serve as a error page for missing routes) they will overrid...
Sounds good - wildcard route is a nice to have for me right now so no biggie, thanks for the explanation!