Catch user already registered Godot

Hi all, I’m trying to catch if user is already registered to the database.
I understand this has been answered here: How should I check if an account already exists to decide if the user should register or login? - Heroic Labs

But godot does not handle exceptions, and that’s not an error to go through the is_exception handler.

I see that the Session returns the values from here:

func _to_string():
	if is_exception():
		return get_exception()._to_string()
	return "Session<created=%s, token=%s, create_time=%d, username=%s, user_id=%s, vars=%s, expire_time=%d, refresh_token=%s refresh_expire_time=%d>" % [
		created, token, create_time, username, user_id, str(vars), expire_time, refresh_token, refresh_expire_time]

The way fthings are for now per docs are:

print("Successfully authenticated: %s" % session)

I’m trying for example to first just print that single variable form that return, but haven’t been able so far.

How should I catch that created bool and handle if user is already registered?
Also, in a side note, is there a place where I can get a list of possible errors and codes to handle them accordingly?

Thanks!

EDIT:

Sorry, I have tried this before but it was throwing an error, I have no idea why I tried again and it worked.
As simple as:

if !session.created:
			print("User already registered")
1 Like

Thanks for sharing your solution.

1 Like

In my case, users can login using Google, Facebook and Apple. When the player is already authenticated using google (for example) and he wants to also connect apple, I want it to succeed in 2 cases:

  • apple account that he is trying to connect is free (isn’t connected to any other user)
  • apple account is linked to the same Nakama user that the google is linked to

In other cases I want to get exception. As far as I investigated there is only one type of exception that Nakama sdk (for unity at least) throws and that is ApiResponseException. The only difference is that it has different status codes of exception. Somehow I found out that status code for Account Already In use is 409, so I can catch it that way, but is this the way? Aren’t there any other options?

Final questions:
How to manage multiple social networks sign in to a same Nakama user? Do I have to have a single Session object for them? Do I have to use “Authenticate” method for each time when player logins to new social network (assume that they are connected to same Nakama user)?

As you might have noticed, I am weak in all that server stuff:( but I am open to reasearch!

Guys, I really need this. I didn’t found any documentation on this…