99 updateUserProfileInfo ,
1010} from "~/datasources/queries/users" ;
1111import { getUsername } from "~/datasources/queries/utils/createUsername" ;
12- import { unauthorizedError } from "~/errors" ;
12+ import { applicationError , ServiceErrors , unauthorizedError } from "~/errors" ;
13+
14+ const preventUserUpdate = new Set < "retool" > ( [ "retool" ] ) ;
1315
1416// Obtener el token de autorización de la solicitud, ya sea del encabezado de
1517// autorización o de la cookie "community-os-access-token"
@@ -25,12 +27,12 @@ const getAuthToken = (request: Request) => {
2527 return null ;
2628} ;
2729
28- export const createAuthToken = async ( user : USER , SECRET : string ) => {
30+ export const createMinimalAuthToken = async ( user : USER , SECRET : string ) => {
2931 const payload = {
30- audience : "retool-autenticated " ,
31- id : user . id ,
32- email : user . email ,
33- user_metadata : user ,
32+ audience : "retool" ,
33+ user_metadata : {
34+ sub : user . id ,
35+ } ,
3436 exp : Date . now ( ) + 60 * 60 * 24 * 1000 /* 24 hours */ ,
3537 } ;
3638
@@ -155,7 +157,18 @@ export const upsertUserFromRequest = async ({
155157
156158 logger . info ( `Updating profile Info for user ID: ${ sub } ` ) ;
157159
158- return updateUserProfileInfo ( DB , profileInfo . data , logger ) ;
160+ if ( payload . audience && preventUserUpdate . has ( payload . audience ) ) {
161+ logger . info ( `Preventing update for user ID: ${ sub } ` ) ;
162+ const user = await findUserByID ( DB , sub ) ;
163+
164+ if ( ! user ) {
165+ throw applicationError ( "User not found" , ServiceErrors . FORBIDDEN , logger ) ;
166+ }
167+
168+ return user ;
169+ } else {
170+ return updateUserProfileInfo ( DB , profileInfo . data , logger ) ;
171+ }
159172} ;
160173
161174export const logPossibleUserIdFromJWT = (
0 commit comments