W
Wasp8mo ago
Karan

Getting error on Google Auth deployed version (using MacOS) and wasp version 0.13.2

Getting "An unknown error occurred while trying to log in with the OAuth provider." Google was working fine on localhost, but once deployed it is no longer working.
15 Replies
kapa.ai
kapa.ai8mo ago
Hi @Karan. 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 information provided, there could be a few potential issues causing the error with Google Auth in your deployed Wasp application. Here are some steps you can take to troubleshoot: 1. Check your Google OAuth configuration: Ensure that your Google OAuth configuration is set up correctly. This includes checking your configFn and userSignupFields in your main.wasp file. The configFn should return an object with the scopes property, and the userSignupFields should reflect the new profile format. You can refer to the migration guide (https://wasp-lang.dev/docs/migrate-from-0-12-to-0-13#migrate-your-oauth-setup) for more details. 2. Update the redirect URLs: The redirect URL for the OAuth providers has changed in Wasp 0.13.0. You will need to update the redirect URL for the OAuth providers in the provider's dashboard. The new format should be {serverUrl}/auth/{provider}/callback. You can refer to the migration guide (https://wasp-lang.dev/docs/migrate-from-0-12-to-0-13#migrate-your-oauth-setup) for more details. 3. Check your environment variables: Ensure that the WASP_SERVER_URL server environment variable is defined and correctly set to the URL of your Wasp server. This is used to generate the redirect URL for the OAuth providers. You can refer to the migration guide (https://wasp-lang.dev/docs/migrate-from-0-12-to-0-13#migrate-your-oauth-setup) for more details. 4. Check your Google OAuth App settings: Ensure that your Google OAuth App settings are correctly configured. This includes setting the correct Authorized redirect URIs, which should be <http://localhost:3001/auth/google/callback> for local development and <https://your-server-url.com/auth/google/callback> for your deployed application. You can refer to the Google Auth setup guide (https://wasp-lang.dev/docs/auth/social-auth/google#3-creating-a-google-oauth-app) for more details. If you've checked all of these and are still experiencing issues, it might be helpful to share more details about your setup or any error messages you're seeing. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Karan, 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?
Filip
Filip8mo ago
Hi @Karan The bot's answer is correct, I believe. If I had to guess, I'd say it's either an issue with redirect URLs in Google's console, or with your environment variables. Make sure you've done everything listed in https://wasp-lang.dev/docs/auth/social-auth/google#3-creating-a-google-oauth-app for both localhost and production.
Google | Wasp
Wasp supports Google Authentication out of the box.
miho
miho8mo ago
We should improve our logging when this happens. Last time a user got this error message, they had issues with connecting to the Google APIs from their localhost (due to using VPN). I've created an issue to add this logging: https://github.com/wasp-lang/wasp/issues/2026
GitHub
Make sure we log OAuth errors in the server console · Issue #2026 ·...
Sometimes users report seeing "An unknown error occurred while trying to log in with the OAuth provider." when things go wrong with the OAuth flow. This message is sent when something une...
Karan
KaranOP8mo ago
The logging might be very helpful to pinpoint the specific issue. Any idea when that will be completed?
miho
miho8mo ago
Soonish 🤷‍♂️ We'll do it soon since it's a simple change. Did you manage to check your env vars and the redirect URL?
Karan
KaranOP8mo ago
I believe I have already done that. But I plan on double checking sometime today.
MEE6
MEE68mo ago
Wohooo @Karan, you just became a Waspeteer level 1!
Karan
KaranOP8mo ago
I manually logged the error before deploying and now I am seeing this: An unknown error occurred while trying to log in with the OAuth provider. Error: DataError: Zero-length key is not supported Figured out this was happening because I missed the JWT_SECRET env variable production deployment. Seems like you guys have a default in Dev.
function getDevelopmentConfig(): EnvConfig {
const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL || 'http://localhost:3000/');
const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL || 'http://localhost:3001');
return {
frontendUrl,
serverUrl,
allowedCORSOrigins: '*',
auth: {
jwtSecret: 'DEVJWTSECRET'
}
}
}
function getDevelopmentConfig(): EnvConfig {
const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL || 'http://localhost:3000/');
const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL || 'http://localhost:3001');
return {
frontendUrl,
serverUrl,
allowedCORSOrigins: '*',
auth: {
jwtSecret: 'DEVJWTSECRET'
}
}
}
But expect it in Production
function getProductionConfig(): EnvConfig {
const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL);
const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL);
return {
frontendUrl,
serverUrl,
allowedCORSOrigins: [frontendUrl],
auth: {
jwtSecret: process.env.JWT_SECRET
}
}
}
function getProductionConfig(): EnvConfig {
const frontendUrl = stripTrailingSlash(process.env.WASP_WEB_CLIENT_URL);
const serverUrl = stripTrailingSlash(process.env.WASP_SERVER_URL);
return {
frontendUrl,
serverUrl,
allowedCORSOrigins: [frontendUrl],
auth: {
jwtSecret: process.env.JWT_SECRET
}
}
}
How can I mark this as solved?
Filip
Filip8mo ago
Hey @Karan That's right. In production, you should make sure you've set all the environment variables your app needs. How you set env variables depends on your auth provider so take a look at their docs. For a full list of the stuff you need to set, check Wasp's deployment docs: https://wasp-lang.dev/docs/advanced/deployment/manually#2-deploying-the-api-server-backend
Karan
KaranOP8mo ago
Would be nice to mention this env variable on the auth pages as a note also since it's only needed of you are using auth. Just a suggestion
Filip
Filip8mo ago
We have an issue that deals with listing all the env variables in a single place, and the comment even mentions JWT_SECRET: https://github.com/wasp-lang/wasp/issues/1894 😄 Still, I think a better single place to list them all is the deployment instructions - because it's depoloyment related and a necessary read before deploying anyway. In other words, when you want to deploy, you'll read the deployment docs, not necessarily the auth docs. But yeah, listing it in the auth docs definitely wouldn't heart either 😅 @Karan just two more questions for you if you'd be so kind: - Did this fix your issue, can I close the ticket? - How come you missed the variable in the deployment docs? So I know what we have to improve Thanks!
GitHub
Document our environment variables · Issue #1894 · wasp-lang/wasp
We should have a table documenting the names, scopes, and uses of all our environment variables. A couple of sections only mention them in passing (manual deployment instructions and configuration ...
Karan
KaranOP8mo ago
Yes please close this now - thank you @sodic I think I started with the opensaas documentation and then missed this deployment step in the wasp documentation I would consider it user error 🤦
martinsos
martinsos8mo ago
While it might be user error, it is on us to make Wasp so nice and good to use that it is hard for users to make an error, so it does help a lot knowing all this, so we can see how we can help somebody in the future avoid the similar error. So thanks for this!
Karan
KaranOP8mo ago
Given that mindset I had an idea, what if there was a validate command as part of the CLI which will check a prod .env file for all expected variables based on the main.wasp
martinsos
martinsos8mo ago
Thanks, that does sound like the right direction! We have an issue related to this open here https://github.com/wasp-lang/wasp/issues/175#issuecomment-2105139654, I just added a comment saying we should do something like this: https://github.com/wasp-lang/wasp/issues/175#issuecomment-2105139654
GitHub
Implement good support for environment variables · Issue #175 · was...
Right now there are some env vars that server requires: PORT, DATABASE_URL, and sometimes JWT_SECRET. We should implement it so in the generated JS code that it fails early if they are missing -&gt...
Want results from more Discord servers?
Add your server