@@ -236,13 +236,11 @@ async function createFirebaseAccount(admin: any, osmID: any, displayName: any, a
236236 // with a variable length.
237237 const uid = `osm:${ osmID } ` ;
238238
239- // check if profile exists on Firebase Realtime Database
240- const snapshot = await admin
241- . database ( )
242- . ref ( `v2/users/${ uid } /` )
243- . once ( )
239+ const profileRef = admin . database ( ) . ref ( `v2/users/${ uid } /` ) ;
244240
245- const profileExists = snapshot . exists ( )
241+ // check if profile exists on Firebase Realtime Database
242+ const snapshot = await profileRef . once ( ) ;
243+ const profileExists = snapshot . exists ( ) ;
246244
247245 // Save the access token to the Firebase Realtime Database.
248246 const databaseTask = admin
@@ -270,14 +268,8 @@ async function createFirebaseAccount(admin: any, osmID: any, displayName: any, a
270268 } ) ;
271269
272270 // Only update display name if profile exists, else create profile
273- const profileUpdateTask = admin
274- . database ( )
275- . ref ( `v2/users/${ uid } /` )
276- . update ( { displayName } ) ;
277-
278- const profileCreationTask = admin
279- . database ( )
280- . ref ( `v2/users/${ uid } /` )
271+ const profileUpdateTask = profileRef . update ( { displayName } ) ;
272+ const profileCreationTask = profileRef
281273 . set ( {
282274 created : new Date ( ) . toISOString ( ) ,
283275 groupContributionCount : 0 ,
0 commit comments