setToken method
Sets the JWT token. @param token The JWT token.
Implementation
@override
void setToken(String token) {
final newUserId = decodeUserIdFromToken(token);
final String? userId = authState?.userId;
if (userId != null && newUserId != userId) {
// We must check that the new token is still using the same user ID.
// We can't accept a re-connection that changes the user ID because the Satellite process is statefull.
// To change user ID the user must re-electrify the database.
throw ArgumentError(
"Can't change user ID when reconnecting. Previously connected with user ID '$userId' but trying to reconnect with user ID '$newUserId'",
);
}
setAuthState(
authState!.copyWith(
userId: () => newUserId,
token: () => token,
),
);
}