pusher / push-notifications-flutter

Official Pusher Beams Flutter client plugin (iOS, Android and Web), receive notifications easily on your Flutter application with Pusher Beams.
https://pub.dev/packages/pusher_beams
MIT License
10 stars 21 forks source link

Setting user ID results in this error: Could not set user id, jwt rejected: Unauthorized: Invalid JWT claims: Token used before issued #35

Closed Milananas closed 1 year ago

Milananas commented 1 year ago

I have seen multiple similar tickets, none has a solution as far as I could find.

My Dart code:

final BeamsAuthProvider provider = BeamsAuthProvider()
  ..authUrl = beamsAuthEndpoint
  ..headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ${jwt!}'
  }
  ..queryParams = {};

await PusherBeams.instance.setUserId(user!.externalId, provider, (error) {
  if (error != null) {
    print(DateTime.now()); // To check for potential time sync issues
    print(error);
  }
});

This is called whenever the app starts and the authenticated event is emitted, or when a user logs in. The token request works fine, a token is returned, however I just can't seem to get the Pusher Beams SDK to work with the returned token.

My server code (runs in NestJS, which handles the conversion to JSON, etc.):

if (userId != user.external_id) {
  throw new UnauthorizedException();
}

const token = this.pusherService
  .getBeamsClient()
  .generateToken(`${user.external_id}`);

return token;

I have synced all servers / clients multiple times to make sure the time is set correctly, I have made sure all devices run on the same timezone (UTC), and am out of ideas.

benw-pusher commented 1 year ago

Hi, It would be good to troubleshoot this through sharing a generated token- however github issues aren't the best place to share such info. Could you open a ticket at https://support.pusher.com/hc/en-us/requests/new and we can investigate with you?

benw-pusher commented 1 year ago

I'll close this out now, if you do need further support please contact us at the link above.