decodeJwt function
Returns the decoded Jwt based on jwt.
Implementation
Jwt decodeJwt(final String jwt) {
try {
final decoded = jsonDecode(
utf8.decode(base64.decode(base64.normalize(jwt.split('.')[1]))),
);
if (decoded is! Map<String, Object?>) {
throw const FormatException('Invalid JWT payload.');
}
final cnf = decoded['cnf'];
if (cnf != null && cnf is! Map) {
decoded.remove('cnf');
}
return Jwt.fromJson(decoded);
} catch (_) {
throw const FormatException('Invalid JWT.');
}
}