docs:api:updateusername
UpdateUsername
public static IEnumerator UpdateUsername(SupabasePreset supabasePreset, string usernameTable, string updatedUsername, System.Action<string> onComplete=null)
Summary:
- Updates the username of the authenticated user in the specified Supabase table.
- This uses the 'Commons' Edge Function - Created during the supabase setup instructionals
- string url = supabasePreset.SupabaseURL + CommonEdgeFunctionURL;
- Users are given a temporary username when they log in for the first time.
- Users can update their username in the profile panel by defualt
- It stores the usernames into the usernames table with the users id, effectively allowing each user to have a unique username.
public void OnSaveUsername()
{
string input = profilePanel.usernameEdit.text.Trim();
// Remove any invalid characters (keeps only letters, numbers, underscores, and dashes)
string cleanUsername = Regex.Replace(input, @"[^a-zA-Z0-9_-]", "");
if (cleanUsername.Length < 3 || cleanUsername.Length > 20)
{
Debug.LogWarning("Username must be between 3 and 20 characters long.");
return;
}
else if (cleanUsername != input)
{
Debug.LogWarning("Username can only contain letters, numbers, underscores, or dashes.");
return;
}
var userData = new Dictionary<string, object>
{
{ "username", cleanUsername }
};
authMain.ShowLoadingScreen();
StartCoroutine(LivelyWebGL.Supabase.Auth.Session.UpdateUsername(
authMain.GetSupabasePreset,
usernameTableName,
cleanUsername,
(rows) =>
{
if (rows.StartsWith("ERROR"))
{
if (cleanUsername == LivelyWebGL.Supabase.Auth.Session.Username)
{
errorHandler.IssueErrorMessage("That's your username!");
}
else
{
errorHandler.IssueErrorMessage("ERROR: " + rows);
}
}
else
{
StartCoroutine(LivelyWebGL.Supabase.Auth.Session.FetchCurrentUser(authMain.GetSupabasePreset, (result)=>
{
FetchPlayerUsername();
}));
CancelEdit();
profilePanel.usernameSaveButton.onClick.RemoveListener(OnSaveUsername);
string message = "Username updated successfully!";
errorHandler.IssueErrorMessage(message);
}
authMain.HideLoadingScreen();
}
));
}
docs/api/updateusername.txt · Last modified: by admin
