feat: add Twitter social login support by updating the auth service and user schema.

This commit is contained in:
pradeepkumar
2025-12-22 16:49:37 +05:30
parent 14e78d80e7
commit 099622dc88
2 changed files with 10 additions and 2 deletions

View File

@@ -30,6 +30,7 @@ enum AuthProvider {
LOCAL LOCAL
GOOGLE GOOGLE
FACEBOOK FACEBOOK
TWITTER
} }
// =========================================== // ===========================================
@@ -49,6 +50,7 @@ model User {
authProvider AuthProvider @default(LOCAL) authProvider AuthProvider @default(LOCAL)
googleId String? @unique googleId String? @unique
facebookId String? @unique facebookId String? @unique
twitterId String? @unique
// Timestamps // Timestamps
createdAt DateTime @default(now()) createdAt DateTime @default(now())

View File

@@ -185,7 +185,11 @@ export class AuthService {
// ========================================== // ==========================================
async socialAuth(dto: SocialAuthDto) { async socialAuth(dto: SocialAuthDto) {
const providerIdField = const providerIdField =
dto.provider === 'google' ? 'googleId' : 'facebookId'; dto.provider === 'google'
? 'googleId'
: dto.provider === 'facebook'
? 'facebookId'
: 'twitterId';
// Check if user exists with this provider ID // Check if user exists with this provider ID
let user = await this.prisma.user.findFirst({ let user = await this.prisma.user.findFirst({
@@ -218,7 +222,9 @@ export class AuthService {
const authProvider = const authProvider =
dto.provider === 'google' dto.provider === 'google'
? AuthProvider.GOOGLE ? AuthProvider.GOOGLE
: AuthProvider.FACEBOOK; : dto.provider === 'facebook'
? AuthProvider.FACEBOOK
: AuthProvider.TWITTER;
// Parse name // Parse name
const nameParts = dto.name?.split(' ') || []; const nameParts = dto.name?.split(' ') || [];