Skip to main content

Connect To Elympics

Authentication

warning

By default, ElympicsLobbyClient performs guest (ClientSecret) authentication. If you want to use Web3 login, you should disable this option by setting authenticateOnAwakeWith to AuthType.None in ElympicsLobbyClient's Inspector. Then be sure to use ConnectToElympicsAsync method.

The ElympicsLobbyClient.Instance.ConnectToElympicsAsync() method is used to establish a connection to the Elympics platform. This process involves authenticating the user and setting up the necessary environment for the game. This function accepts an argument in the form of ConnectionData. Depending on which fields are filled in ConnectionData, different outcomes can be expected:

  • AuthFromCacheData if the field is not null, you will be logged in using these cached authentication details and remaining fields will be ignored. It is also a way to provide external authentication, like when using the PlayPad

  • AuthType the field determines the type of authentication to be used. AuthType.ClientSecret is used as guest authentication.

  • Region the field specifies the server location to which you will connect. If only the Region is provided, it will change the region and reconnect to the WebSocket.

tip

Important things to have at mind when using ConnectToElympicsAsync()

  • Default region is warsaw.
  • This is an asynchronous method. After calling it, you should only allow the user to interact with the game or fetch leaderboards once the connection process is complete.
  • You should not call this method if the user is already authenticated, unless you have a specific reason.
  • It is recommended to use the Start method instead of Awake for initializing the connection to ensure that all components are fully initialized before attempting to authenticate.

Checking Authentication and Connection Status

Elympics SDK separates authentication and connection statuses. The connection status informs us about the connection to the WebSocket, while the authentication status provides information about the available AuthData, indicating how we are authenticated in Elympics.

  • To check if the user is authenticated, you can use: ElympicsLobbyClient.Instance.IsAuthenticated.
  • To check if the WebSocket is connected, you can use: ElympicsLobbyClient.Instance.WebSocketSession.IsConnected.

AuthData

The AuthData structure provides information about the user's authentication status in Elympics. It contains the following properties:

  • UserId
    • Description: A unique identifier for the user.
  • JwtToken
    • Description: The JWT associated with the user's session.
  • AuthType
    • Description: The type of authentication used for the user.
  • Nickname
    • Description: The nickname of the user.

Sign Out

If needed, you can sign out the user by calling: ElympicsLobbyClient.Instance.SignOut().

It is important to do so beforehand if you want to change the authentication method.