Oauth redirects to localhost:3001 instead of 3000

Hello guys, i am using the saas template with Google Oauth. But when I try the Google auth it does not work and redirects to http://localhost:3001/auth/google/login instead of http://localhost:3000/auth/google/login. Any idea what i am doing wrong here ?
12 Replies
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
I believe that’s to be expected. Your server is running on port 3001 so it’s requesting the login details. When you set up Google Auth in Google cloud you have to configure it to redirect to the client. Check out the docs here https://wasp-lang.dev/docs/auth/social-auth/google#3-creating-a-google-oauth-app
Google | Wasp
Wasp supports Google Authentication out of the box.
franckeinstein
franckeinsteinOP11mo ago
I configured google Auth by exactly following the tutorial you just shared. the only difference being that i added userinfo.email in the scope. I configured the URI redirect like this: http://localhost:3000/auth/login/google as in the tutorial. should i make it: http://localhost:3001/auth/login/google ? I don't know, maybe i am missing sth here. and 50% of the time I get this error: "[email protected] start [Server] > npm run validate-env && NODE_PATH=dist node -r dotenv/config dist/server.js [Server]
[Server]
[Server] > [email protected] validate-env [Server] > node -r dotenv/config ./scripts/validate-env.mjs [Server]
[Server] 🔍 Validating environment variables... [Server] 🚀 "Email and password" auth initialized [Server!] file:///Users/fsndzomga/Documents/web-dev-wasp/repliq/.wasp/out/server/dist/auth/providers/oauth/init.js:36 [Server!] throw new Error(The ${provider.displayName} auth provider requires clientID provided via env variables.); [Server!] ^ [Server!] [Server!] Error: The Google auth provider requires clientID provided via env variables. [Server!] at ensureValidConfig (file:///Users/fsndzomga/Documents/web-dev-wasp/repliq/.wasp/out/server/dist/auth/providers/oauth/init.js:36:15) [Server!] at init (file:///Users/fsndzomga/Documents/web-dev-wasp/repliq/.wasp/out/server/dist/auth/providers/oauth/init.js:18:9) [Server!] at async file:///Users/fsndzomga/Documents/web-dev-wasp/repliq/.wasp/out/server/dist/auth/providers/index.js:12:11 [Server!] [Server!] Node.js v18.12.0 [Server] [nodemon] app crashed - waiting for file changes before starting..."
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
Ok. Let’s check a couple things: 1. What’s your main.wasp file look like? Specifically the auth methods section? Have you added google:{}? 2. Have you already logged in with the same email address using the Email method? For example, if you are logging in with Google with email [email protected], did you previously use [email protected] with the Email and Password method? If so, run wasp db studio and delete that user and try logging in again. 3. Have you added the Google client id and secret to your .env.server file? From the error message it looks like you haven’t provided number 3
franckeinstein
franckeinsteinOP11mo ago
1. "auth: { userEntity: User, externalAuthEntity: SocialLogin, methods: { email: { fromField: { name: "Repliq App", // make sure this address is the same you registered your SendGrid or MailGun account with! email: "[email protected]" }, emailVerification: { clientRoute: EmailVerificationRoute, getEmailContentFn: import { getVerificationEmailContent } from "@server/auth/email.js", }, passwordReset: { clientRoute: PasswordResetRoute, getEmailContentFn: import { getPasswordResetEmailContent } from "@server/auth/email.js", }, }, google: { // Guide for setting up Auth via Google https://wasp-lang.dev/docs/auth/social-auth/overview getUserFieldsFn: import { getUserFields } from "@server/auth/google.js", configFn: import { config } from "@server/auth/google.js", }, }, onAuthFailedRedirectTo: "/", }," 2. No. All the tables are empty (see images) 3. Yes (see images)
Overview | Wasp
Social login options (e.g., Log in with Google) are a great (maybe even the best) solution for handling user accounts.
No description
No description
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
Any ideas here @miho ? @franckeinstein can you paste the contents of your app/src/server/auth/google.ts file as a code snippet using three backticks at the start and at the end of the code ```
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
Ah it looks like you’re using our outdated saas template! Have you done a lot of changes to the code? You should use https://opensaas.sh instead.
Open SaaS
Free, open-source SaaS boilerplate starter for React & NodeJS.
franckeinstein
franckeinsteinOP11mo ago
Okay thanks for the help. I haven't done a lot of change to the code. I guess the part of the documentation where it is recommended to do "wasp new <project-name> -t saas" should be updated then. In the meantime, I will use the new template thanks.
MEE6
MEE611mo ago
Wohooo @franckeinstein, you just became a Waspeteer level 1!
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
yeah you're right if you dont mind, you can send me a link to the github repo you have now and I can try it out myself tomorrow and see where the problem lies. But definitely try out open saas instead
franckeinstein
franckeinsteinOP11mo ago
it's the one from ""wasp new <project-name> -t saas". I don't know how to get the github link, but maybe it was some issue on my part. The latest saas template you shared works perfectly
miho
miho11mo ago
@Vinny (@Wasp) we still haven't released 0.12 which would point to the new saas template, the 0.11.8 points to the old template @franckeinstein sorry about the mix up, 0.12 is coming soon 😊
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
awesome!
Want results from more Discord servers?
Add your server