heroiclabs / nakama-defold

Defold client for Nakama server.
https://heroiclabs.com
Apache License 2.0
74 stars 12 forks source link

Nakama authentication returns an error on iOS #67

Closed totebo closed 1 year ago

totebo commented 1 year ago

Authenticating with Nakama returns this error when using nakama.authenticate_device(), nakama.authenticate_custom(), nakama.authenticate_apple(), nakama.authenticate_game_center() and nakama.authenticate_email() on iOS:

ERROR:SCRIPT: HTTP request to 'http://127.0.0.1:7350/v2/account/authenticate/apple?username=Niclas&create=true' failed (http result: -1  socket result: -24)
DEBUG:SCRIPT: 
{ --[[0x10b469ad0]]
  message = "Unable to decode response",
  error = true
} 

This line (and probably some other logs): https://github.com/heroiclabs/nakama-defold/blob/master/nakama/engine/defold.lua#L67

Returns this:

DEBUG:SCRIPT: /v2/account/authenticate/device    with coroutine
DEBUG:SCRIPT: HTTP    POST    http://127.0.0.1:7350/v2/account/authenticate/device?username=Niclas&create=true
DEBUG:SCRIPT: DATA    {"id":"ccac5124-3e27-49c8-c93a-020000000000"}

Using nakama.authenticate_device(), nakama.authenticate_custom() and nakama.authenticate_email() works in the local Defold player on Mac.

totebo commented 1 year ago

It turns out that this is the default error message when no connection can be made. When testing I incorrectly used 127.0.0.1 on both the Mac and the iPhone. This means the iPhone tried to connect to its own localhost, which of course doesn't work.

The solution to test locally is to find the actual local IP of the server and use that for external devices.

britzl commented 1 year ago

Oh, good to hear that you managed to figure it out!