Link multiple OAuth providers to one account
Let one user sign in with both Google and GitHub.
A user signs up with email/password. Later they click "Connect GitHub" — now both providers point at the same NestAuthUser.
Default behavior
When a user is logged in and calls POST /auth/login with an OAuth credential whose provider isn't yet linked, the library:
- Validates the OAuth token.
- Checks
nest_auth_identitiesfor(provider, providerId). - If no row exists, creates one — bound to the currently logged-in user rather than creating a new one.
So the simplest "link" flow is just calling login while authenticated:
Listing linked identities
(this.identities here is the standard TypeORM Repository<NestAuthIdentity>.)
Unlinking
The library doesn't ship an unlink endpoint — write your own:
Email-collision policy
If the OAuth provider returns an email that already belongs to a different user, the default behavior is to link to that user (one-step account merge). If you'd rather refuse and force the user to log in to the existing account first, override it: