find-or-create with social login -- SaaS template

Using the SaaS template, is there a way to get a sort of find-or-create behavior from social login? Take this case, for example: I go to /signup and signup with GitHub. I have an email [email protected]. If I try to go to /login and log in with google, the existing user should be found and logged in, no? What I’m seeing is that I get an error: “Save failed: user with the same identity already exists”. Wasp v0.14.0
7 Replies
kapa.ai
kapa.ai3mo ago
Hi @JakeLoew. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Currently, Wasp does not support multiple auth identities for a single user out of the box. This means that a user can't have both a GitHub-based auth identity and a Google-based auth identity. This is why you are seeing the "Save failed: user with the same identity already exists" error when you try to log in with Google after signing up with GitHub using the same email address source (https://github.com/wasp-lang/wasp/issues/1817). However, there is an open issue on the Wasp GitHub repository to improve the user account merging logic. The proposed solution is to allow an optional user-defined function to check if a user is already associated with the incoming social auth method/id and create a new user if there is no association. This would allow you to associate a GitHub user and a Google user with the same email to the same user account source (https://github.com/wasp-lang/wasp/issues/954). In the meantime, you could potentially implement a workaround by manually checking if a user with the same email already exists in your database and associating the new auth method with the existing user. However, this would require custom code and is not supported by Wasp's built-in auth system. For more information on how Wasp handles social logins, you can check out the Wasp documentation (https://wasp-lang.dev/docs/auth/social-auth/overview). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @JakeLoew, 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?
JakeLoew
JakeLoew3mo ago
Great, thanks. You are a very smart support bot.
Filip
Filip3mo ago
Yeah, it sometimes surprises me too 😄 I'm adding this chat to the issue to prioritize it
JakeLoew
JakeLoew3mo ago
@kapa.ai Is it possible to roll my own OAuth with wasp? I'm confident in part of the process, but still have several unknowns. Knowns: - Remove gitHub from my auth object in main.wasp - Set up a github oauth app with an authorized redirect uri of an api I establish in main.wasp - Write the handler for the /callback api endpoint and authorize with github Unknowns: - Once I get the user's identity from github, how to I set them as the signed in user in wasp?
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Wasp currently supports GitHub OAuth out of the box, and you can enable it by adding gitHub: {} to the auth.methods dictionary in your main.wasp file source (https://wasp-lang.dev/docs/auth/social-auth/github#default-behaviour). However, if you want to implement your own OAuth flow, you would need to handle the OAuth process manually, including setting up the GitHub OAuth app, handling the callback, and exchanging the authorization code for an access token. Once you have the user's identity from GitHub, you would need to create a new user in your database or find an existing user with the same identity. Wasp automatically creates a new user and links it to the auth provider account when a user signs in for the first time source (https://wasp-lang.dev/docs/auth/social-auth/github#default-behaviour). Unfortunately, Wasp does not currently provide a built-in way to manually set a user as signed in. The user's signed-in state is managed internally by Wasp's auth system, and there is no public API for changing this state. If you need more control over the auth process, you might need to wait for future updates to Wasp's auth system or consider using a different framework that provides more flexibility. You can also follow the progress of Wasp's auth system in the Wasp GitHub repository (https://github.com/wasp-lang/wasp). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @JakeLoew, 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
miho3mo ago
Here's a recent gist I've created for Spotify, should be enough to get you started 🙂 https://gist.github.com/infomiho/3c63de7d53aba59d6293bcb59501a029 It's not perfect, but we will improve your ability to integrate better over time.
Gist
Implementing custom OAuth provider with Wasp 0.14.0+ (Spotify in th...
Implementing custom OAuth provider with Wasp 0.14.0+ (Spotify in this case) - main.wasp
JakeLoew
JakeLoew3mo ago
thank you! I'll be following along on this feature!
Want results from more Discord servers?
Add your server