authenticateDevice method

  1. @override
Future<Session> authenticateDevice({
  1. required String deviceId,
  2. bool create = true,
  3. String? username,
  4. Map<String, String>? vars,
})
override

Device authentication

Nakama Device Authentication uses the physical device’s unique identifier to easily authenticate a user and create an account if one does not exist.

When using only device authentication, you don’t need a login UI as the player can automatically authenticate when the game launches.

Implementation

@override
Future<model.Session> authenticateDevice({
  required String deviceId,
  bool create = true,
  String? username,
  Map<String, String>? vars,
}) async {
  final request = api.AuthenticateDeviceRequest()
    ..create_2 = api.BoolValue(value: create)
    ..account = (api.AccountDevice()
      ..id = deviceId
      ..vars.addAll(vars ?? {}));

  if (username != null) {
    request.username = username;
  }

  final res = await _client.authenticateDevice(request);

  return model.Session.fromDto(res);
}