Tutorial API implementation doesn't work for me.
my main.wasp is
my src/api/api.jsx is
code compiles with no problems, but localhost:3000/api endpoint returns 401 instead of the api response. any ideas?
22 Replies
Hi @devrim. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The issue you're experiencing might be related to the authentication setting in your API declaration. In your
main.wasp
file, you have set auth: false
, which means that the API does not attempt to parse the JWT in the Authorization Header. However, if the request to the API includes an Authorization Header, and the JWT is invalid or expired, the server might still return a 401 Unauthorized error.
If you're sure that the request does not include an Authorization Header, or that the JWT is valid, then the issue might be elsewhere. It could be related to the middleware configuration, or it could be a bug in Wasp. There is an open issue on the Wasp GitHub repository about providing more information during development when an error happens on the server, which might be related to your problem (source (https://github.com/wasp-lang/wasp/issues/91)).
As a first step, I would suggest to check the request you're sending to the API, and make sure it does not include an Authorization Header, or that the JWT is valid. If that doesn't solve the problem, you might want to look into customizing the middleware configuration, as described in the Wasp documentation (https://wasp-lang.dev/docs/advanced/middleware-config).
If none of these suggestions help, I would recommend to open a new issue on the Wasp GitHub repository (https://github.com/wasp-lang/wasp/issues), providing as much information as possible about your problem. The Wasp team is usually very responsive and will be able to help you troubleshoot the issue.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @devrim, 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?just hitting the url with localhost:3000/api with no JWT - github issue is not helpful.
ok cursor AI helped, if i do localhost:3001/api then it works..
Wohooo @devrim, you just became a Waspeteer level 1!
but this doesn't solve how i access that endpoint when the app is deployed...
Depends where you deploy your backend. The API is part of your backend server. So you need to use the url of your backend server.
If you used the standard wasp config and deployed it to fly.io your backend server address will look probably something like this: https://<yourAppname>-server.fly.dev
So for example:
https://devrim-server.fly.dev/api
hi that makes sense, but i'm getting a forever spinning wheel when i hit the deployed URL
@Gwaggli if you can take a look.
ok i'm sorry this is nothing to do with the api endpoint, it was complaining about the google oauth token, and not running the server at all. if you guys know what it's complaining about google token i'd appreciate that (followed the tutorial there fully as well) but if not please disregard the api not working request. thank you!
I am not using google oAuth so not sure, but seems like you are missing some env variables? Does it work locally, right? Did you set the env variables in fly.io as well? Personal/Videoupdate-server/Secrets? (https://fly.io/apps/videoupdate-server/secrets)
Which template are you using? How does your Wasp file look like, are you using Google auth? Did you set the env variables on Fly?
Maybe this is your issue, is your redirect url on localhost rather than pointing to the hosted domain
You also have these errors, indicating your env doesnt have the values for google auth have you added that yet? (keep in mind .env is in .gitignore you have to add it on the server)
all problems here have been resolved with your help. thank you very much!
im getting this error and cannot figure out what is going on. i have the GOOGLE_CLIENT_ID in my .env.server file, but somehow I guess fly is not picking it up on my redeploys
ok it turns out my issue was fixed by setting the env vars on fly manually as described here: https://wasp-lang.dev/docs/advanced/deployment/cli#environment-variables-1
my question is then why I am also setting them in .env.server and/or why these are not pull from the .env.server file and set for my automatically as part of deployment. I think this is also related to the issue here: https://github.com/wasp-lang/wasp/issues/2053
If I understand properly, you are asking why your env files are not pushed ? They are in .gitignore/.dockerignore so it doesnt leak info/keys.You should always set them manually when you deploy somewhere regardless of where you deploy and what frameworks you use