@@ -259,52 +259,35 @@ class EditProfileController extends GetxController {
259259
260260 // Update USERNAME
261261 if (isUsernameChanged ()) {
262- var usernameAvail = await isUsernameAvailable (
263- usernameController.text.trim (),
264- );
265- if (! usernameAvail) {
266- usernameAvailable.value = false ;
267- customSnackbar (
268- AppLocalizations .of (Get .context! )! .usernameUnavailable,
269- AppLocalizations .of (Get .context! )! .usernameAlreadyTaken,
270- LogType .error,
271- );
272-
273- SemanticsService .announce (
274- AppLocalizations .of (Get .context! )! .usernameAlreadyTaken,
275- TextDirection .ltr,
276- );
277- return ;
278- }
279-
280- // Create new doc of New Username
281- await databases.createDocument (
282- databaseId: userDatabaseID,
283- collectionId: usernameCollectionID,
284- documentId: usernameController.text.trim (),
285- data: {'email' : authStateController.email},
286- );
287-
288262 try {
289- // Delete Old Username doc, so Username can be re-usable
290- await databases.deleteDocument (
263+ await databases.createDocument (
291264 databaseId: userDatabaseID,
292265 collectionId: usernameCollectionID,
293- documentId: oldUsername,
266+ documentId: usernameController.text.trim (),
267+ data: {'email' : authStateController.email},
268+ );
269+
270+ try {
271+ await databases.deleteDocument (
272+ databaseId: userDatabaseID,
273+ collectionId: usernameCollectionID,
274+ documentId: oldUsername,
275+ );
276+ } catch (e) {
277+ log (e.toString ());
278+ }
279+
280+ await databases.updateDocument (
281+ databaseId: userDatabaseID,
282+ collectionId: usersCollectionID,
283+ documentId: authStateController.uid! ,
284+ data: {"username" : usernameController.text.trim ()},
294285 );
295286 } catch (e) {
296287 log (e.toString ());
288+ rethrow ;
297289 }
298-
299- await databases.updateDocument (
300- databaseId: userDatabaseID,
301- collectionId: usersCollectionID,
302- documentId: authStateController.uid! ,
303- data: {"username" : usernameController.text.trim ()},
304- );
305- }
306-
307- //Update user DISPLAY-NAME
290+ } //Update user DISPLAY-NAME
308291 if (isDisplayNameChanged ()) {
309292 // Update user DISPLAY-NAME and USERNAME
310293 await authStateController.account.updateName (
0 commit comments