W
Wasp-langβ€’3mo ago
fred-123

Google auth not working in production

I had set up google auth in dev and it worked without problems but it cause a lot of problems in production. I am using the opensaas template. The documentation doesn't really mention how to get it working for production. I have set up the oauth app and credentials in google and passed the client id and secret to fly through cli. It doesn't throw an error but also doesn't log the user in when atempting to log in with google. I feel like there is no accurate documentation for this. The open saas documentation mentions that only the google auth part has to be uncommented and a google oauth app has to be created but that doesn't go further than dev stage. Even when passing the client id and secret to fly it doesn't seem to work. Is there any better documentation about this somewhere?
36 Replies
kapa.ai
kapa.aiβ€’3mo ago
Hi @fred-123. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I understand your frustration and I'm here to help. Based on the knowledge sources provided, it seems like you've done most of the steps correctly. However, there are a few things you might want to check: 1. Google OAuth App Configuration: Make sure that you have added the correct redirect URIs in your Google OAuth App. For production, you should add your production server URL to the list of authorized redirect URIs. For example: <https://your-server-url.com/auth/google/callback.> You can check this in your Google Cloud Console here (https://console.cloud.google.com/home/dashboard). 2. Environment Variables: Ensure that you have added the Google Client ID and Client Secret to your .env.server file. This file should be at the root of your project and should look something like this:
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
You can find more details about this in the Wasp documentation (https://wasp-lang.dev/docs/auth/social-auth/google#4-adding-environment-variables). 3. User Signup Fields: Make sure that your userSignupFields and configFn match the latest implementation. An outdated implementation might cause issues. Here's an example of how it should look:
export const getGoogleUserFields = defineUserSignupFields({
email: (data: any) => data.profile.emails[0].value,
username: (data: any) => data.profile.displayName,
isAdmin: (data: any) => adminEmails.includes(data.profile.emails[0].value),
});
export const getGoogleUserFields = defineUserSignupFields({
email: (data: any) => data.profile.emails[0].value,
username: (data: any) => data.profile.displayName,
isAdmin: (data: any) => adminEmails.includes(data.profile.emails[0].value),
});
You can find more details about this in the Wasp Discord community (https://discord.com/channels/686873244791210014/1222916615151161374). If you've checked all of these and it's still not working, I would recommend reaching out to the Wasp community on Discord for further assistance. They are very helpful and might be able to provide more specific guidance based on your situation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @fred-123, 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?
miho
mihoβ€’3mo ago
Open SaaS is a template for the Wasp framework, have you checked the revelant docs for Google auth here: https://wasp-lang.dev/docs/auth/social-auth/google
Google | Wasp
Wasp supports Google Authentication out of the box.
fred-123
fred-123β€’3mo ago
@miho I have over and over again. I noticed something odd. My version of opensaas seems to be quite different from the one on github. I got opensaas a month or two ago and started with wasp 0.13. I have since migrated to wasp 0.14. For example here is my google auth code from main.wasp: // Uncomment to enable Google Auth (check https://wasp-lang.dev/docs/auth/social-auth/google for setup instructions): google: { // Guide for setting up Auth via Google userSignupFields: import { getGoogleUserFields } from "@src/server/auth/setUsername.js", configFn: import { getGoogleAuthConfig } from "@src/server/auth/setUsername.js", but it looks like this on gituhub: // Uncomment to enable Google Auth (check https://wasp-lang.dev/docs/auth/social-auth/google for setup instructions): // google: { // Guide for setting up Auth via Google // userSignupFields: import { getGoogleUserFields } from "@src/auth/userSignupFields", // configFn: import { getGoogleAuthConfig } from "@src/auth/userSignupFields", // },
Google | Wasp
Wasp supports Google Authentication out of the box.
miho
mihoβ€’3mo ago
I think we updated the template a bit, yep πŸ˜„ 1. What do you see in your browser console? Share a screenshot 2. What do you see in your app on the login page? Share a screenshot 3. What do you see in the server terminal? Share a screenshot if there are some errors
fred-123
fred-123β€’3mo ago
Does that mean with my version of open saas the documentation won't work for me anymore and i have to rebuild it with the new template?
miho
mihoβ€’3mo ago
@Vinny (@Wasp) one for you
miho
mihoβ€’3mo ago
Ok, I think I know what's up The docs say
Once you know on which URL(s) your API server will be deployed, also add those URL(s). For example: https://your-server-url.com/auth/google/callback
The key detail is - server URL, and not the client URL Which Wasp version are you using?
fred-123
fred-123β€’3mo ago
I tried that to and i get another error. It then says something like uri mismatch. Let me try and find the exact error i upgrade to 0.14 yesterday
miho
mihoβ€’3mo ago
Did you deploy the 0.14 version? That's good, I suspect you have an older Wasp version deployed - the URI mismatch confirms that
fred-123
fred-123β€’3mo ago
I had the site deployed using wasp 0.13 initially and then redeployed after doing the update to 0.14. Did i miss something else i have to do? How can i confirm the wasp version of the deployed app? Shouldn't it be also updated to wasp 0.14 when i redeploy or is that not how it works? What do you suggest i do now? Take the deployed website down and run wasp deploy fly launch again? Rebuild the entire site with the new template? I have been trying a bunch of stuff over the past 3 days and just can't get it to work. I have read and tried everything in the documentation but there just seems to be a lot of differences between the opensaas template i am using and the current one. Is there any way to get the templates to match again without having to start over again? How do others solve that problem that use the opensaas template?
miho
mihoβ€’3mo ago
Which commands did you run to deploy the new version of the app? Did you follow the migration guide? Did you get any errors that might suggest the deployment didn't go through? @Vinny (@Wasp) @matija maybe you can give some ideas here
fred-123
fred-123β€’3mo ago
I did but i skipped the steps such as "Replace the getUsername helper with user.identities.username.id", "6. Migrate Prisma preview features config to the schema.prisma file", "Replace the getEmail helper with user.identities.email.id", "Replace accessing providerData with user.identities.<provider>.<value>", "Use getFirstProviderUserId directly on the user object", "Replace findUserIdentity with checks on user.identities.<provider>" as i couldn't find any occurences of these in my codebase. I ran: REACT_APP_STRIPE_CUSTOMER_PORTAL=https://billing.stripe.com/p/login/test_somethingmadeup wasp deploy fly deploy
fred-123
fred-123β€’3mo ago
I tried wasp clean and wasp build now and build fails. I get type mismatch errors:
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
can you remove the radius property from the barchart.tsx file and try again ?
fred-123
fred-123β€’3mo ago
trying that now i get this when trying to run wasp clean: wasp clean 🐝 --- Deleting the .wasp/ directory... ------------------------------------------- wasp-bin: /Users/username/Saas-Website/app/.wasp/: removeDirectoryRecursive:removeContentsRecursive:removeDirectory: unsatisfied constraints (Directory not empty) built doesn't fail anymore I closed all terminal windows and ran wasp clean again and now it didn't throw an error
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
ok cool and build works too?
fred-123
fred-123β€’3mo ago
trying right now build also worked now will try deploying when running wasp 0.14 but still using the old template from open saas. Should it still work or would i have to find all the parts that changed and implement them into my code to get google auth working in production? deploying to fly worked
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
awesome. then it was just the BarChart issue glad we could get it resolved
fred-123
fred-123β€’3mo ago
Yeah i still have the initial issue with google auth though
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
oh if you've migrated to 0.14 without errors then it should work
fred-123
fred-123β€’3mo ago
I have changed the authorized redirecs uri back to the fly server url: https://myapp-server.fly.dev/auth/google/callback i still get this when trying to use it; Error 400: redirect_uri_mismatch fly status -a myapp-server App Name = myapp-server Owner = personal Hostname = myapp-server.fly.dev
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
i don't think you need to add an Authorized Domain
fred-123
fred-123β€’3mo ago
it adds itself automaticly when adding the callback url for Authorized redirect URIs
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
ok then make sure your fly server has this env var added
WASP_SERVER_URL=https://marketplacetools-server.fly.dev
WASP_SERVER_URL=https://marketplacetools-server.fly.dev
fred-123
fred-123β€’3mo ago
oh ok ran that now
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
ok redploy and see if it works
fred-123
fred-123β€’3mo ago
will do thanks for that. That might be what i missed. I was using fly comands for setting the server url it still doesn't work will try deleting browser cache to see if that does something still get the 400: redirect_uri_mismatch when trying to log in or signup with google wait i think i ran the command incorrectly. I have to run flyctl secrets set WASP_SERVER_URL=https://myapp-server.fly.dev -a myapp right? I ran that and at least i get a different error now. After trying to signup up with google i get: Validation failed: Cannot read properties of undefined (reading '0') its working!
MEE6
MEE6β€’3mo ago
Wohooo @fred-123, you just became a Waspeteer level 6!
fred-123
fred-123β€’3mo ago
I have edited the getGoogleUserFields function in setUsername.ts to this: export const getGoogleUserFields = defineUserSignupFields({ email: (data: any) => { if (data.profile && data.profile.emails && data.profile.emails.length > 0) { return data.profile.emails[0].value; } return null; // or throw an error if email is required }, username: (data: any) => data.profile?.displayName || null, isAdmin: (data: any) => { if (data.profile && data.profile.emails && data.profile.emails.length > 0) { return adminEmails.includes(data.profile.emails[0].value); } return false; }, }); @Vinny (@Wasp) @miho Thank you so much for taking the time and pointing me in the right direction. I was struggling with this for several days and just couldn't figure it out.
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
Ah ok you must have been migrating from 0.12
miho
mihoβ€’3mo ago
I'm glad you figured it out 😊
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
Glad it’s working
fred-123
fred-123β€’3mo ago
I don't think so. I just migrated yesterday and when i ran wasp version it returned 0.13.something I just started with opensaas in june. @Vinny (@Wasp) you are right. I must have done the upgrade to 0.13 in some sleepless night and entirely forgot about it. I don't recall updating to wasp 0.13 and don't know why I haven't used the latest version of wasp when initially setting up open saas. I went through the migration docs for 0.12 -> 0.13 now and it cleared up a lot of errors that I had.
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
awesome! no worries. let us know if you need any more help
fred-123
fred-123β€’3mo ago
Apreciate all the help! Without you guys i would still be stuck on that. It didn't even cross my mind that that could be the problem. Will do!
Want results from more Discord servers?
Add your server