set-nickname
BACKND Guidelines > 1. Implementing Login/Sign-up > Step 4. Implementing Nickname Change
Implementing Nickname Change
1. Write the nickname change method
Add content to the UpdateNickname method in BackendLogin.cs written in Pre-arrangements.
BackendLogin.cs
Before editing
public void UpdateNickname(string nickname) {
// Logic for Step 4. Implementing Nickname Change
}
After editing
public void UpdateNickname(string nickname) {
Debug.Log("Requesting nickname change.");
var bro = Backend.BMember.UpdateNickname(nickname);
if(bro.IsSuccess()) {
Debug.Log("Nickname change successful : " + bro);
} else {
Debug.LogError("Nickname change failed : " + bro);
}
}
2. Add method call to BackendManager.cs
BackendManager, which is automatically called when the game is executed, must be used to call this method.
Add it so that the method may be called after BACKND initialization.
BackendManager.cs Before editing
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1","1234"); // [Addition] BACKND login
Debug.Log("Test complete.");
});
}
After editing
async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1","1234"); // [Addition] BACKND login
BackendLogin.Instance.UpdateNickname("Desired nickname"); // [Addition] Change nickname
Debug.Log("Test complete.");
});
}
3. Test in Unity
After editing the script, execute Unity debugging and check the console log of Unity.
The method has been successfully called when the log displays 'Nickname change successful. : statusCode : 204'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which error caused the failure in UpdateNickname error case.
When statusCode : 409 error occurs
When changing the nickname 2 or more times without changing the logic, this error occurs due to the command attempting to change the nickname to a preexisting one.
The parameter value that goes inside UpdateNickname of BackendManager.cs should be changed to a value different from the nickname that was originally entered.
4. Check in the console
Go to BACKND Console, and in BACKND Base > User Management
check that the changed nickname is displayed properly for the logged-in user.