Skip to content

Commit

Permalink
Fixes broken getAccount() on device auth
Browse files Browse the repository at this point in the history
  • Loading branch information
obrunsmann committed Jun 4, 2021
1 parent 61e604c commit 0ea7542
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/src/nakama_client/nakama_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class NakamaRestApiClient extends NakamaBaseClient {
final res = await _api.nakamaAuthenticateDevice(
body: ApiAccountDevice(
id: deviceId,
vars: {'foo': 'bar'},
),
create: create,
username: username,
Expand Down Expand Up @@ -300,7 +301,14 @@ class NakamaRestApiClient extends NakamaBaseClient {
final res = await _api.nakamaGetAccount();

final acc = Account();
acc.mergeFromProto3Json(res.body!.toJson());
// Some workaround here while protobuf expects the vars map to not be null
acc.mergeFromProto3Json((res.body!.copyWith(
devices: res.body!.devices!
.map((e) => e.copyWith(
vars: e.vars ?? {},
))
.toList(),
)).toJson());

return acc;
}
Expand Down
29 changes: 29 additions & 0 deletions test/rest/account_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:faker/faker.dart';
import 'package:nakama/api/api.pb.dart' as api;
import 'package:nakama/nakama.dart';
import 'package:nakama/src/nakama_client/nakama_api_client.dart';
import 'package:test/scaffolding.dart';
import 'package:test/test.dart';

void main() {
group('[REST] Test Account', () {
late final NakamaBaseClient client;
late final Session session;

setUpAll(() async {
client = NakamaRestApiClient.init(
host: '127.0.0.1',
ssl: false,
serverKey: 'defaultkey',
);

session = await client.authenticateDevice(deviceId: faker.guid.guid());
});

test('fetching my account', () async {
final account = await client.getAccount(session);

expect(account, isA<api.Account>());
});
});
}

0 comments on commit 0ea7542

Please sign in to comment.