Signing Game Users Up (JS)
Let players make an account in your game. The account belongs to your game, so the player can sign in from any device and keep their data.
Sign a player up¶
Call GameFuse.signUp from your sign-up form, after GameFuse.setUpGame has finished.
// Call this from your sign-up form's submit button.
function signUp(email, password, username) {
// The third value is the password confirmation: pass the same password again.
GameFuse.signUp(email, password, password, username, function (message, hasError) {
if (hasError) {
console.error('Sign-up failed: ' + message);
return;
}
const player = GameFuseUser.CurrentUser;
console.log('Signed up and signed in as ' + player.getUsername());
});
}
signUp('jane@example.com', 'secret-password', 'jane');
GameFuse.signUp(email, password, passwordConfirmation, username, callback):
| Value | What it is |
|---|---|
email |
The player's email. They sign in with it, and password reset emails go to it. |
password |
At least 6 characters. |
passwordConfirmation |
The password again. If it does not match, sign-up fails. |
username |
The name shown on leaderboards. It must be unique in your game. |
callback |
Called with (message, hasError) when done. |
A successful sign-up also signs the player in: GameFuseUser.CurrentUser is now this player, with their token, credits, score, data and purchased items downloaded. You do not need to call signIn after it.
When sign-up fails¶
The callback gets hasError = true. In this version of the library the message is always User could not sign up: undefined; it does not say why. The usual reasons are:
- the email or the username is already used in this game,
- the password is shorter than 6 characters,
- the two passwords are different,
- the game's username screening refused the name.
Check the password length and the two passwords in your form before calling signUp, and ask the player to try another email or username otherwise.
There is no email verification step: the account works straight away.
Next: Signing Game Users In.