Environment variable I need to add to Railway to get GoogleOAuth to work
I am getting this error in Railway:
π Validating environment variables...
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_URL]: Invalid URL
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:637:13)
at getRedirectUriForCallback (/app/.wasp/out/sdk/wasp/server/auth/oauth/redirect.ts:33:10)
at <anonymous> (/app/.wasp/out/sdk/wasp/server/auth/oauth/providers/google.ts:18:3)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
input: 'undefined/auth/google/callback',
code: 'ERR_INVALID_URL'
}
Google OAuth worked in Heroku for me, and all the env variables have been copied from there
6 Replies
Hi @AC. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the error message you're seeing, it appears that you're missing the
WASP_SERVER_URL
environment variable in your Railway deployment. This is causing the error when trying to construct the callback URL for Google OAuth.
The error specifically shows that it's trying to create a URL with "undefined/auth/google/callback", which indicates that the base URL (which should come from WASP_SERVER_URL) is undefined.
For Google OAuth to work properly in Wasp 0.13.0 and later, you need to set the following environment variables in Railway:
1. WASP_SERVER_URL
- This is required and should be the URL where your server is running (e.g., <https://your-app-name.up.railway.app
>)
2. GOOGLE_CLIENT_ID
- Your Google OAuth client ID
3. GOOGLE_CLIENT_SECRET
- Your Google OAuth client secret
According to the migration guide from Wasp 0.12.X to 0.13.X, Wasp introduced a new required server environment variable WASP_SERVER_URL
that's used to generate the redirect URL for OAuth providers:
In 0.13.0 Wasp introduces a new server env variable WASP_SERVER_URL
that you need to define. This is the URL of your Wasp server and it's used to generate the redirect URL for the OAuth providers.
Migration from 0.12.X to 0.13.X
Also, make sure you've updated the redirect URLs in your Google OAuth configuration to use the new format:
Instead of the old format:
You'll need to add this redirect URL in your Google Cloud Console OAuth configuration.
Deploying Manually - Environment Variables
If you've already set these variables and are still experiencing issues, double-check that the WASP_SERVER_URL
value is correct and doesn't have any trailing slashes, as that has been known to cause CORS errors in some cases.
GitHub: Martinsos
GitHub: Martinsos
GitHub: Martinsos
GitHub: Martinsos
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @AC, 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?Thanks, Kapa! missed adding that variable. Works now!
Which variable exactly? π the
WASP_SERVER_URL
?WASP_SERVER_URL π
I should have noted it. I'm launching tomorrow, and ran into a last minute issue with Heroku, so was rushing through the switch to Railway, which my mentor suggested. This was definitely a user issue, not a Wasp issue.
Hopefully Wasp should have told in the server logs that something is off with the env vars. Which Wasp version are you using? π
Yes, it did! I just couldn't figure out which env var it was though because I was rushing. I'm still on the previous version (0.15), will have to update post launch. The rush is because I started this project on Nov 1, and it was supposed to launch on March 1...Had to do a full refactor in March based on alpha testing and QA results almost entirely because my first go at coding was...not great. So then had to redo almost all the DB operations, refactor the frontend, etc. I'm launching it today since it's now solidly passing QA and alpha testing.
Sorry, looking through the error messages again, it didn't specifically tell me it was an env var issue, but there was more than enough info to figure out that this was the issue. The key message was TypeError [ERR_INVALID_URL]: Invalid URL... Pretty self-evident that this was caused by an environment variable being missing in production.