- Remove OtpGateGuard from transactions controller (OTP verified at login) - Fix categories controller to use authenticated user instead of TEMP_USER_ID - Add comprehensive implementation plan document - Update .env.example with WEB_APP_URL - Prepare for admin dashboard development
5.2 KiB
5.2 KiB
✅ Profile Fixes - FINAL
🔧 Fixes Applied:
1. Google Auth Detection Fixed ✅
Problem: Still showing "Change Password" for Google users
Root Cause:
- Was checking
/api/auth/accountsendpoint (doesn't exist yet) - Fallback logic wasn't working
Solution:
- Changed to use
/api/users/auth-infoendpoint - Backend needs to return:
{ "hasGoogleAuth": boolean, "hasPassword": boolean }
Backend Endpoint Needed:
GET /api/users/auth-info
Response: {
hasGoogleAuth: boolean, // User has Google OAuth linked
hasPassword: boolean // User has password hash (not null)
}
Logic:
- hasGoogleAuth: Check if user has Google OAuth account linked
- hasPassword: Check if user.passwordHash !== null
2. Removed Duplicate Phone Field ✅
Problem: Phone field appears in both:
- Edit Profile tab
- Security tab (2FA section)
Solution:
- ✅ Removed phone field from 2FA section
- ✅ Kept phone field in Edit Profile tab only
- ✅ Added phone display in WhatsApp OTP section
- ✅ Updated alert message to reference Edit Profile tab
Changes:
- WhatsApp OTP section now shows: "Phone: +1234567890"
- Alert: "Please add your phone number in the Edit Profile tab first"
- No duplicate input fields
📊 Current Structure:
Edit Profile Tab:
├── Avatar (with upload for non-Google)
├── Name (editable for non-Google)
├── Email (readonly)
└── Phone Number (editable) ← ONLY PLACE TO EDIT PHONE
Security Tab:
├── Change Password / Set Password
│ └── (conditional based on hasPassword)
│
├── Two-Factor Authentication
│ ├── WhatsApp OTP
│ │ ├── Phone: +1234567890 (display only)
│ │ ├── Enable/Disable button
│ │ └── Alert if no phone
│ │
│ ├── Email OTP
│ │ └── Enable/Disable button
│ │
│ └── TOTP (Authenticator App)
│ └── Setup/Disable
│
└── Danger Zone
└── Delete Account
🔧 Backend Requirements:
New Endpoint: GET /api/users/auth-info
@Get('auth-info')
async getAuthInfo(@CurrentUser() user: User) {
// Check if user has Google OAuth
const googleAccount = await this.prisma.account.findFirst({
where: {
userId: user.id,
provider: 'google'
}
})
return {
hasGoogleAuth: !!googleAccount,
hasPassword: user.passwordHash !== null
}
}
Existing Endpoint: POST /api/auth/set-password
@Post('set-password')
async setPassword(
@CurrentUser() user: User,
@Body() body: { newPassword: string }
) {
// Check user doesn't have password
if (user.passwordHash !== null) {
throw new BadRequestException('User already has a password')
}
// Hash and set password
const hashedPassword = await bcrypt.hash(body.newPassword, 10)
await this.prisma.user.update({
where: { id: user.id },
data: { passwordHash: hashedPassword }
})
return { success: true }
}
✅ UI Flow:
Google User Without Password:
- Go to Security tab
- See "Set Password" card
- See alert: "Your account uses Google Sign-In..."
- No "Current Password" field
- Enter New Password + Confirm
- Click "Set Password"
- Success! Can now delete account
Google User With Password:
- Go to Security tab
- See "Change Password" card
- See "Current Password" field
- Enter Current + New + Confirm
- Click "Update Password"
- Success!
WhatsApp OTP Setup:
- Go to Edit Profile tab
- Add phone number
- Click "Update"
- Go to Security tab
- See WhatsApp OTP section
- See "Phone: +1234567890"
- Click "Enable WhatsApp OTP"
- Enter code
- Success!
🧪 Testing:
Test 1: Google User Detection
- Login with Google
- Go to Security tab
- Should see "Set Password" (not "Change Password")
- Should see alert about Google Sign-In
- Should NOT see "Current Password" field
Test 2: Set Password
- Enter new password + confirm
- Click "Set Password"
- Success message appears
- Page reloads
- Now shows "Change Password"
- Now shows "Current Password" field
Test 3: Phone Field
- Go to Edit Profile tab
- See phone field ✅
- Go to Security tab
- Do NOT see phone input field ✅
- See phone display in WhatsApp section ✅
Test 4: WhatsApp OTP
- No phone → See alert "add phone in Edit Profile tab"
- Add phone in Edit Profile
- Go back to Security
- See "Phone: +1234567890"
- Can enable WhatsApp OTP
✅ ESLint: Clean
npm run lint
# ✓ 0 errors, 0 warnings
📝 Summary:
Fixed:
- ✅ Google auth detection (changed endpoint)
- ✅ Removed duplicate phone field
- ✅ Added phone display in WhatsApp section
- ✅ Updated alert messages
Backend Needed:
GET /api/users/auth-info- Return hasGoogleAuth and hasPasswordPOST /api/auth/set-password- Create password for Google user
Result:
- ✅ Clean UI (no duplicates)
- ✅ Proper Google user detection
- ✅ Phone managed in one place
- ✅ Clear user guidance
Ready for backend implementation! 🚀