Skip to content

v6.0.0

Latest
Compare
Choose a tag to compare
@jondubois jondubois released this 02 Jun 18:58
· 13 commits to master since this release

Breaking change:

  • Affects asyngular-client: For WebSocket-based JWT authentication, the flow has been simplified. Before, login used to be implemented like this:
// Client code

let credentials = {
  username: 'alice123',
  password: 'thisisapassword654'
};

try {
  // Invoke a custom 'login' procedure (RPC) on our server socket.
  await socket.invoke('login', credentials);
} catch (error) {
  // showLoginError(err);
  return;
}
await socket.listener('authenticate').once();

// goToMainScreen();

This approach will no longer work (it will get stuck) because the authenticate event will trigger sooner (before the login response has been received). The recommended approach is now this:

// Client code

let credentials = {
  username: 'alice123',
  password: 'thisisapassword654'
};

try {
  // Invoke a custom 'login' procedure (RPC) on our server socket
  // then wait for the socket to be authenticated.
  await Promise.all([
    socket.invoke('login', credentials),
    socket.listener('authenticate').once()
  ]);
} catch (error) {
  // showLoginError(err);
  return;
}

// Socket is authenticated!
// goToMainScreen();

Depending on your implementation of the login method, you may not need to listen to the authenticate event at all.