fromBackendData static method
Implementation
static MiniProgramAuthSession fromBackendData({
required String miniProgramId,
required Map<String, dynamic> data,
required DateTime nowUtc,
}) {
final authenticated = data['authenticated'];
if (authenticated == false) {
throw const FormatException('Auth response is not authenticated.');
}
final rawUser = data['user'];
final idToken = data['idToken'];
final refreshToken = data['refreshToken'];
if (rawUser is! Map) {
throw const FormatException('Auth response requires a user object.');
}
if (idToken is! String || idToken.trim().isEmpty) {
throw const FormatException('Auth response requires an idToken.');
}
if (refreshToken is! String || refreshToken.trim().isEmpty) {
throw const FormatException('Auth response requires a refreshToken.');
}
final expiresAtUtc = _parseAuthExpiry(data, nowUtc);
return MiniProgramAuthSession(
miniProgramId: miniProgramId.trim(),
user: MiniProgramAuthUser.fromJson(Map<String, dynamic>.from(rawUser)),
idToken: idToken.trim(),
refreshToken: refreshToken.trim(),
expiresAtUtc: expiresAtUtc,
);
}