How to Save User Data After Google Login (Next.js + Express + MongoDB) #1134
-
Hi everyone, I'm currently developing a full-stack application using Next.js (TypeScript) for the frontend and Express for the backend. I've implemented Google OAuth login, but I'm unsure about the best timing and method to store user data into MongoDB. Here's the general flow I'm considering:
Does this approach seem correct? Or are there better patterns for this? I'd appreciate any advice especially on the following:
Thanks in advance for your insights! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @constant-infinite! 👋 Your flow looks solid and is a common pattern for Google OAuth in full-stack apps. Here’s a quick breakdown and some tips: |
Beta Was this translation helpful? Give feedback.
-
🔐 JWT vs. Session Cookies: |
Beta Was this translation helpful? Give feedback.
Hey @constant-infinite! 👋 Your flow looks solid and is a common pattern for Google OAuth in full-stack apps. Here’s a quick breakdown and some tips:
✅ Yes, your flow is correct:
Frontend triggers Google login → gets id_token
Send id_token to backend (POST /auth/google)
Backend verifies token (using google-auth-library)
Extracts user info → checks MongoDB
Creates user if new, or returns existing user