chore: refactor user profile repository for UUID (refs #214)
Updated user-profile.repository.ts to use UUID instead of auth0_sub: - Added getById(id) method for UUID-based lookups - Changed all methods (except getByAuth0Sub, getOrCreate) to accept userId (UUID) instead of auth0Sub - Updated SQL WHERE clauses from auth0_sub to id for UUID-based queries - Fixed cross-table joins in listAllUsers and getUserWithAdminStatus to use user_profile_id - Updated hardDeleteUser to use UUID for all DELETE statements - Updated auth.plugin.ts to call updateEmail and updateEmailVerified with userId (UUID) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -166,9 +166,9 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
|
||||
|
||||
// If profile has placeholder email but we now have real email, update it
|
||||
if (profile.email.includes('@unknown.local') && email && !email.includes('@unknown.local')) {
|
||||
await profileRepo.updateEmail(auth0Sub, email);
|
||||
await profileRepo.updateEmail(userId, email);
|
||||
logger.info('Updated profile with correct email from Auth0', {
|
||||
userId: auth0Sub.substring(0, 8) + '...',
|
||||
userId: userId.substring(0, 8) + '...',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,16 +184,16 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
|
||||
try {
|
||||
const isVerifiedInAuth0 = await auth0ManagementClient.checkEmailVerified(auth0Sub);
|
||||
if (isVerifiedInAuth0 && !profile.emailVerified) {
|
||||
await profileRepo.updateEmailVerified(auth0Sub, true);
|
||||
await profileRepo.updateEmailVerified(userId, true);
|
||||
emailVerified = true;
|
||||
logger.info('Synced email verification status from Auth0', {
|
||||
userId: auth0Sub.substring(0, 8) + '...',
|
||||
userId: userId.substring(0, 8) + '...',
|
||||
});
|
||||
}
|
||||
} catch (syncError) {
|
||||
// Don't fail auth if sync fails, just log
|
||||
logger.warn('Failed to sync email verification status', {
|
||||
userId: auth0Sub.substring(0, 8) + '...',
|
||||
userId: userId.substring(0, 8) + '...',
|
||||
error: syncError instanceof Error ? syncError.message : 'Unknown error',
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user