Heroic Labs Documentation

Guarding APIs #

There are many reasons why you may want to limit or completely prevent client access to any or all of the Nakama APIs, such as performing any desired validation on a client request or preventing client attempts at circumventing your game logic.

Nakama provides multiple avenues for you to secure your game against malicious client actions:

  • Implementing game logic on the server as RPCs or hooks
  • Setting access controls on storage objects. Objects created via the REST API will always be owned by the authenticated user and you can set if other players have read access to this data by setting the read permissions accordingly.
  • Server-to-server calls can be secured via HTTP key.
  • Use before hooks to disable any APIs you don’t want to be directly accessible by clients.

Using before hooks #

To disable any API, register a before hook on the function call you want to disable and instead of returning the request input, return nil. Nakama will automatically handle any such scenario as a disabled API call.

In the example implementation provided below, any message names and API calls that are commented out remain available to clients while all others are disabled:

Server
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
package metagame

import (
  "context"
  "database/sql"

  "github.com/heroiclabs/nakama-common/api"
  "github.com/heroiclabs/nakama-common/rtapi"
  "github.com/heroiclabs/nakama-common/runtime"
)

func registerGuard(initializer runtime.Initializer) error {
  rtMessages := []string{
    //"ChannelJoin",
    //"ChannelLeave",
    //"ChannelMessageSend",
    "ChannelMessageUpdate",
    "ChannelMessageRemove",
    "MatchCreate",
    //"MatchDataSend",
    //"MatchJoin",
    //"MatchLeave",
    "MatchmakerAdd",
    "MatchmakerRemove",
    "PartyCreate",
    "PartyCreate",
    "PartyJoin",
    "PartyLeave",
    "PartyPromote",
    "PartyAccept",
    "PartyRemove",
    "PartyClose",
    "PartyJoinRequestList",
    "PartyMatchmakerAdd",
    "PartyMatchmakerRemove",
    "PartyDataSend",
    //"Ping",
    //"Pong",
    //"Rpc",
    "StatusFollow",
    "StatusUnfollow",
    "StatusUpdate",
  }
  for _, rtMessage := range rtMessages {
    if err := initializer.RegisterBeforeRt(rtMessage, func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) (*rtapi.Envelope, error) {
      return nil, nil
    }); err != nil {
      return err
    }
  }

  if err := initializer.RegisterBeforeGetAccount(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule) error {
    return nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUpdateAccount(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeSessionRefresh(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.SessionRefreshRequest) (*api.SessionRefreshRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeAuthenticateApple(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateAppleRequest) (*api.AuthenticateAppleRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateCustom(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeAuthenticateDevice(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateEmail(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeAuthenticateFacebook(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateFacebookInstantGame(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateFacebookInstantGameRequest) (*api.AuthenticateFacebookInstantGameRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeAuthenticateGameCenter(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeAuthenticateGoogle(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateSteam(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeListChannelMessages(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeListFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListFriendsRequest) (*api.ListFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeAddFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeDeleteFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeBlockFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeImportFacebookFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeCreateGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUpdateGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeDeleteGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeJoinGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeLeaveGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  // if err := initializer.RegisterBeforeAddGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  if err := initializer.RegisterBeforeBanGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.BanGroupUsersRequest) (*api.BanGroupUsersRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  // if err := initializer.RegisterBeforeKickGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforePromoteGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeDemoteGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DemoteGroupUsersRequest) (*api.DemoteGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeListGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeListUserGroups(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeListGroups(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  if err := initializer.RegisterBeforeDeleteLeaderboardRecord(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListLeaderboardRecords(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeWriteLeaderboardRecord(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListLeaderboardRecordsAroundOwner(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkApple(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountApple) (*api.AccountApple, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkCustom(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkDevice(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkEmail(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkFacebook(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkFacebookInstantGame(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebookInstantGame) (*api.AccountFacebookInstantGame, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkGameCenter(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeLinkGoogle(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkSteam(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LinkSteamRequest) (*api.LinkSteamRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListMatches(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeListNotifications(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  // if err := initializer.RegisterBeforeDeleteNotification(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  if err := initializer.RegisterBeforeListStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeReadStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeWriteStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeDeleteStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeJoinTournament(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListTournamentRecords(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListTournaments(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeWriteTournamentRecord(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListTournamentRecordsAroundOwner(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUnlinkApple(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountApple) (*api.AccountApple, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeUnlinkCustom(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUnlinkDevice(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeUnlinkEmail(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUnlinkFacebook(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebook) (*api.AccountFacebook, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeUnlinkFacebookInstantGame(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebookInstantGame) (*api.AccountFacebookInstantGame, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUnlinkGameCenter(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUnlinkGoogle(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUnlinkSteam(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeGetUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.GetUsersRequest) (*api.GetUsersRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }

  return nil
}
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
let InitModule: nkruntime.InitModule = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer) {
  // initializer.registerRtBefore("ChannelJoin", guardFunction);
  // initializer.registerRtBefore("ChannelLeave", guardFunction);
  // initializer.registerRtBefore("ChannelMessageSend", guardFunction);
  initializer.registerRtBefore("ChannelMessageUpdate", guardFunction);
  initializer.registerRtBefore("ChannelMessageRemove", guardFunction);
  initializer.registerRtBefore("MatchCreate", guardFunction);
  // initializer.registerRtBefore("MatchDataSend", guardFunction);
  // initializer.registerRtBefore("MatchJoin", guardFunction);
  // initializer.registerRtBefore("MatchLeave", guardFunction);
  initializer.registerRtBefore("MatchmakerAdd", guardFunction);
  initializer.registerRtBefore("MatchmakerRemove", guardFunction);
  // initializer.registerRtBefore("Ping", guardFunction);
  // initializer.registerRtBefore("Pong", guardFunction);
  initializer.registerRtBefore("StatusFollow", guardFunction);
  initializer.registerRtBefore("StatusUnfollow", guardFunction);
  initializer.registerRtBefore("StatusUpdate", guardFunction);
  // initializer.registerBeforeUpdateAccount(guardFunction);
  // initializer.registerBeforeAuthenticateApple(guardFunction);
  initializer.registerBeforeAuthenticateCustom(guardFunction);
  // initializer.registerBeforeAuthenticateDevice(guardFunction);
  initializer.registerBeforeAuthenticateEmail(guardFunction);
  // initializer.registerBeforeAuthenticateFacebook(guardFunction);
  initializer.registerBeforeAuthenticateFacebookInstantGame(guardFunction);
  // initializer.registerBeforeAuthenticateGameCenter(guardFunction);
  // initializer.registerBeforeAuthenticateGoogle(guardFunction);
  initializer.registerBeforeAuthenticateSteam(guardFunction);
  // initializer.registerBeforeListChannelMessages(guardFunction);
  initializer.registerBeforeListFriends(guardFunction);
  initializer.registerBeforeAddFriends(guardFunction);
  initializer.registerBeforeDeleteFriends(guardFunction);
  initializer.registerBeforeBlockFriends(guardFunction);
  initializer.registerBeforeImportFacebookFriends(guardFunction);
  initializer.registerBeforeCreateGroup(guardFunction);
  initializer.registerBeforeUpdateGroup(guardFunction);
  initializer.registerBeforeDeleteGroup(guardFunction);
  initializer.registerBeforeJoinGroup(guardFunction);
  initializer.registerBeforeLeaveGroup(guardFunction);
  // initializer.registerBeforeAddGroupUsers(guardFunction);
  initializer.registerBeforeBanGroupUsers(guardFunction);
  // initializer.registerBeforeKickGroupUsers(guardFunction);
  // initializer.registerBeforePromoteGroupUsers(guardFunction);
  // initializer.registerBeforeDemoteGroupUsers(guardFunction);
  // initializer.registerBeforeListGroupUsers(guardFunction);
  // initializer.registerBeforeListUserGroups(guardFunction);
  // initializer.registerBeforeListGroups(guardFunction);
  initializer.registerBeforeDeleteLeaderboardRecord(guardFunction);
  initializer.registerBeforeListLeaderboardRecords(guardFunction);
  initializer.registerBeforeWriteLeaderboardRecord(guardFunction);
  initializer.registerBeforeListLeaderboardRecordsAroundOwner(guardFunction);
  // initializer.registerBeforeLinkApple(guardFunction);
  initializer.registerBeforeLinkCustom(guardFunction);
  // initializer.registerBeforeLinkDevice(guardFunction);
  initializer.registerBeforeLinkEmail(guardFunction);
  // initializer.registerBeforeLinkFacebook(guardFunction);
  initializer.registerBeforeLinkFacebookInstantGame(guardFunction);
  // initializer.registerBeforeLinkGameCenter(guardFunction);
  // initializer.registerBeforeLinkGoogle(guardFunction);
  initializer.registerBeforeLinkSteam(guardFunction);
  // initializer.registerBeforeListNotifications(guardFunction);
  // initializer.registerBeforeDeleteNotifications(guardFunction);
  initializer.registerBeforeListStorageObjects(guardFunction);
  initializer.registerBeforeReadStorageObjects(guardFunction);
  initializer.registerBeforeWriteStorageObjects(guardFunction);
  initializer.registerBeforeDeleteStorageObjects(guardFunction);
  initializer.registerBeforeJoinTournament(guardFunction);
  initializer.registerBeforeListTournamentRecords(guardFunction);
  initializer.registerBeforeListTournaments(guardFunction);
  initializer.registerBeforeWriteTournamentRecord(guardFunction);
  initializer.registerBeforeListTournamentRecordsAroundOwner(guardFunction);
  // initializer.registerBeforeUnlinkApple(guardFunction);
  initializer.registerBeforeUnlinkCustom(guardFunction);
  // initializer.registerBeforeUnlinkDevice(guardFunction);
  initializer.registerBeforeUnlinkEmail(guardFunction);
  // initializer.registerBeforeUnlinkFacebook(guardFunction);
  initializer.registerBeforeUnlinkFacebookInstantGame(guardFunction);
  initializer.registerBeforeUnlinkGameCenter(guardFunction);
  initializer.registerBeforeUnlinkSteam(guardFunction);
  initializer.registerBeforeGetUsers(guardFunction);
}

const guardFunction = function() {
  return null;
};

// Reference InitModule to avoid it getting removed on build
!InitModule && InitModule.bind(null);
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
It is not possible to return null to guard against the registerBeforeGetAccount function in the TypeScript server runtime. If you do need to guard this function in TypeScript, you can instead throw an error e.g. throw new Error("Function disabled"). Please be aware that this will generate error logs in Nakama.