Skip to content

Commit 9ccd890

Browse files
authored
fix(realtime): Send version when joining channel and remove jwt check (#1166)
1 parent f33c9fe commit 9ccd890

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

packages/realtime_client/lib/src/realtime_client.dart

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -410,36 +410,18 @@ class RealtimeClient {
410410
final tokenToSend =
411411
token ?? (await customAccessToken?.call()) ?? accessToken;
412412

413-
if (tokenToSend != null) {
414-
Map<String, dynamic>? parsed;
415-
try {
416-
final decoded =
417-
base64.decode(base64.normalize(tokenToSend.split('.')[1]));
418-
parsed = json.decode(utf8.decode(decoded));
419-
} catch (e) {
420-
// ignore parsing errors
421-
}
422-
if (parsed != null && parsed['exp'] != null) {
423-
final now = (DateTime.now().millisecondsSinceEpoch / 1000).floor();
424-
final valid = now - parsed['exp'] < 0;
425-
if (!valid) {
426-
log(
427-
'auth',
428-
'InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed['exp']}',
429-
null,
430-
Level.FINE,
431-
);
432-
throw FormatException(
433-
'InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed['exp']}');
434-
}
435-
}
413+
if (accessToken == tokenToSend) {
414+
return;
436415
}
437416

438417
accessToken = tokenToSend;
439418

440419
for (final channel in channels) {
441420
if (tokenToSend != null) {
442-
channel.updateJoinPayload({'access_token': tokenToSend});
421+
channel.updateJoinPayload({
422+
'access_token': tokenToSend,
423+
'version': Constants.defaultHeaders['X-Client-Info'],
424+
});
443425
}
444426
if (channel.joinedOnce && channel.isJoined) {
445427
channel.push(ChannelEvents.accessToken, {'access_token': tokenToSend});

packages/realtime_client/test/socket_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ void main() {
453453

454454
group('setAuth', () {
455455
final token = generateJwt();
456-
final updateJoinPayload = {'access_token': token};
456+
final updateJoinPayload = {
457+
'access_token': token,
458+
'version': Constants.defaultHeaders['X-Client-Info'],
459+
};
457460
final pushPayload = {'access_token': token};
458461

459462
test(
@@ -534,7 +537,10 @@ void main() {
534537

535538
const token = 'sb-key';
536539
final pushPayload = {'access_token': token};
537-
final updateJoinPayload = {'access_token': token};
540+
final updateJoinPayload = {
541+
'access_token': token,
542+
'version': Constants.defaultHeaders['X-Client-Info'],
543+
};
538544

539545
await mockedSocket.setAuth(token);
540546

0 commit comments

Comments
 (0)