W
Wasp-lang•3mo ago
WulfCoDev

Enabling Auth Required Isnt Routing to /login

When I enable authRequired: true in my main.wasp, its not routing to what onAuthFailedRedirectTo is set to. Rather I get a network error and Mozillas console is stating CORS error. I didnt used to get this error so Im unsure on how to remediate it. Any Help appreciated. Wasp Version 0.14.0. I am using Supabase as an external DB if that could be creating an issue.
No description
No description
11 Replies
kapa.ai
kapa.ai•3mo ago
Hi @WulfCoDev. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The authRequired: true property in your main.wasp file should indeed redirect unauthenticated users to the route specified in onAuthFailedRedirectTo. If this is not happening, it could be due to a variety of reasons. The CORS error you're seeing typically occurs when a web application tries to access resources from a different domain, and the server doesn't allow it. This is a security feature implemented in web browsers to prevent malicious requests. Here are a few things you could check: 1. Ensure that your onAuthFailedRedirectTo is correctly set in your main.wasp file. It should look something like this:
app myApp {
// ...
auth: {
// ...
onAuthFailedRedirectTo: "/login",
},
}
app myApp {
// ...
auth: {
// ...
onAuthFailedRedirectTo: "/login",
},
}
2. Check if the route you're redirecting to ("/login" in this case) is correctly defined and accessible. 3. If you're making requests to a different domain, ensure that the server is set up to allow CORS from your domain. This is typically done on the server-side, and the exact steps can vary depending on the server technology used. 4. If you're using any browser extensions that might interfere with CORS, try disabling them to see if that resolves the issue. If none of these steps help, it might be a good idea to ask for help in the Wasp Discord community (https://discord.com/channels/686873244791210014/1216511333176971366) or open an issue on the Wasp GitHub page (https://github.com/wasp-lang/wasp/issues). Sources: - Wasp Auth Overview (https://wasp-lang.dev/docs/auth/overview#onauthfailedredirectto-string-) - Wasp Discord Community (https://discord.com/channels/686873244791210014/1216511333176971366) - Wasp GitHub Issues (https://github.com/wasp-lang/wasp/issues) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @WulfCoDev, 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?
WulfCoDev
WulfCoDev•3mo ago
this new error in the terminal also appears.
No description
IamIconLiving
IamIconLiving•3mo ago
hey, do you have the login page created? like it says here
7. Adding Authentication | Wasp
Most modern apps need a way to create and authenticate users. Wasp makes this as easy as possible with its first-class auth support.
IamIconLiving
IamIconLiving•3mo ago
looks like wasp fails to find the UI to render on the /login route
WulfCoDev
WulfCoDev•3mo ago
yes, everything works and loads until i add the auth required line in main.wasp. Trying to login or create an account gives the same network error
IamIconLiving
IamIconLiving•3mo ago
can you show your main.wasp and your login component that is being used in /login route?
MEE6
MEE6•3mo ago
Wohooo @IamIconLiving 🌶, you just became a Waspeteer level 12!
miho
miho•3mo ago
@WulfCoDev the redirect doesn't work because the client can't check with backend if the user is logged in or not. It can't check with the backend because of the CORS error 😄 Let's debug that! You are running this on your computer locally? Are you opening the client on localhost:3000? Which OS are you using? Did you change any of the env vars e.g. WASP_WEB_CLIENT_URL?
WulfCoDev
WulfCoDev•3mo ago
yes im running local host 3000 with server on 3001. I didnt initially have env variables for the client and server url so i added them and reran wasp start and it seemed to fix it although i removed it as a test to see if it would recreate the error and it did not but it is currently working as supposed to Im currently on ubuntu wsl but i was first running into the issue on ubuntu desktop i have installed onto a mac mini thats my main developer machine.
MEE6
MEE6•3mo ago
Wohooo @WulfCoDev, you just became a Waspeteer level 1!
WulfCoDev
WulfCoDev•3mo ago
I appreciate the help, if im able to recreate the issue and fix, ill notify
Want results from more Discord servers?
Add your server