Error when trying to login with google oauth

I recently migrated my codebase from 0.12.4 to 0.13.0 and I'm now having issues when I attempt to login or signup through google. My google config looks like this:
export function getGoogleAuthConfig() {
return {
scopes: ['profile', 'email'], // must include at least 'profile' for Google
};
}
export function getGoogleAuthConfig() {
return {
scopes: ['profile', 'email'], // must include at least 'profile' for Google
};
}
My google get user fields looks like this:
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),
});
and I've added the correct redirect uri to my google cloud console as well. Can someone help me figure out what's going wrong here.
7 Replies
kapa.ai
kapa.ai4mo ago
Hi @rithvik12345678. 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 you've provided and the knowledge sources, there are a few things you could check: 1. Check your OAuth setup: Ensure that you have correctly updated your OAuth setup as per the migration guide from 0.12.X to 0.13.X. Specifically, make sure you have updated the configFn and userSignupFields fields to use the new profile format. For example, the displayName field should now be accessed via data.profile.name instead of data.profile.displayName (source (https://wasp-lang.dev/docs/migrate-from-0-12-to-0-13#migrate-your-oauth-setup)). 2. Check your OAuth provider's data format: Wasp now directly forwards what it receives from the OAuth providers. You can check the data format for Google in Wasp's docs (source (https://wasp-lang.dev/docs/migrate-from-0-12-to-0-13#migrate-your-oauth-setup)). 3. Check for unique constraint violations: If a user tries to sign up with the same email address using different OAuth providers, it could lead to unique constraint violations if the email field in your User entity has a unique constraint. This could cause the user to be redirected back to the login page without any error message being displayed (source (https://github.com/wasp-lang/wasp/issues/1817)). 4. Check your environment variables: Ensure that you have added the Google client id and secret to your .env.server file (source (https://discord.com/channels/686873244791210014/1208366712450195466)). If you've checked all of these and are still experiencing issues, it might be helpful to provide any error messages you're seeing for further troubleshooting. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @rithvik12345678, 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?
rithvik12345678
rithvik123456784mo ago
None of these apply to me. @miho do you know anything about this
mindreaderlupoDO
https://discord.com/channels/686873244791210014/1222916615151161374 This thread helped me to fix that issue, I changed the getGoogleUserFields function
miho
miho4mo ago
What kind of errors do you get? What happens when you try to log in with Google?
rithvik12345678
rithvik123456784mo ago
@miho on the website it says "Validation failed: Cannot read properties of undefined (reading '0')" and I get a 302 error like this: [ Server ] GET /auth/google/callback?state=O2iVwcODfjJZIK7ECMODSp8DBXRfKvWYcYKBL7FvHIY&code=4%2F0AeaYSHCxB3qukDB9eCvMHcnerCnOWCpqwEfw1TJ5yBDXecnWDtAMmUeYxMreeJvYsWI4Zw&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+openid&authuser=0&prompt=consent 302 675.053 ms - - in the terminal
miho
miho4mo ago
@Vinny (@Wasp) this sounds like old code again?
Vinny (@Wasp)
Vinny (@Wasp)4mo ago
Yep. You’ll want to update your code to match this: https://github.com/wasp-lang/open-saas/blob/main/app/src/server/auth/setUsername.ts#L29-L39 We had to make some small changes in auth for the new wasp version
GitHub
open-saas/app/src/server/auth/setUsername.ts at main · wasp-lang/op...
A free, open-source SaaS app starter for React & Node.js with superpowers. Production-ready. Community-driven. - wasp-lang/open-saas