@@ -4,8 +4,10 @@ import { z } from "zod";
44
55import { ORM_TYPE } from "~/datasources/db" ;
66import {
7+ allowedUserUpdateForAuth ,
78 insertUsersSchema ,
89 selectUsersSchema ,
10+ updateUsersSchema ,
911 usersSchema ,
1012 UserStatusEnum ,
1113} from "~/datasources/db/schema" ;
@@ -55,17 +57,17 @@ export const updateUserProfileInfo = async (
5557 } else {
5658 logger . info ( "User found — updating user" ) ;
5759 // we update the user
60+ const updateData = allowedUserUpdateForAuth . parse ( {
61+ externalId : parsedProfileInfo . externalId ,
62+ name : parsedProfileInfo . name ,
63+ imageUrl : parsedProfileInfo . imageUrl ,
64+ isEmailVerified : parsedProfileInfo . isEmailVerified ,
65+ publicMetadata : parsedProfileInfo . publicMetadata ?? { } ,
66+ status : UserStatusEnum . active ,
67+ } ) ;
5868 const updatedUsers = await db
5969 . update ( usersSchema )
60- . set ( {
61- externalId : parsedProfileInfo . externalId ,
62- name : parsedProfileInfo . name ,
63- imageUrl : parsedProfileInfo . imageUrl ,
64- isEmailVerified : parsedProfileInfo . isEmailVerified ,
65- publicMetadata : parsedProfileInfo . publicMetadata ?? { } ,
66- updatedAt : sql `current_timestamp` ,
67- status : UserStatusEnum . active ,
68- } )
70+ . set ( updateData )
6971 . where ( eq ( usersSchema . email , parsedProfileInfo . email ) )
7072 . returning ( ) ;
7173 const updatedUser = updatedUsers ?. [ 0 ] ;
@@ -75,6 +77,8 @@ export const updateUserProfileInfo = async (
7577 throw new Error ( "Could not update user" ) ;
7678 }
7779
80+ logger . info ( "User updated" ) ;
81+
7882 return selectUsersSchema . parse ( updatedUser ) ;
7983 }
8084} ;
0 commit comments