Session.fromJson constructor
Creates a Session instance from a JSON response.
The json map should contain the keys as defined by the Better Auth API.
Example:
final session = Session.fromJson({
'id': 'session_123',
'token': 'abc123',
'expiresAt': '2024-12-31T23:59:59Z',
'user': {...},
});
Implementation
factory Session.fromJson(Map<String, dynamic> json) {
return Session(
id: json['id'] as String,
user: User.fromJson(json['user'] as Map<String, dynamic>),
token: json['token'] as String,
expiresAt: json['expiresAt'] != null
? DateTime.parse(json['expiresAt'] as String)
: DateTime.now().add(const Duration(days: 30)),
ipAddress: json['ipAddress'] as String?,
userAgent: json['userAgent'] as String?,
isCurrent: json['isCurrent'] as bool? ?? false,
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'] as String)
: DateTime.now(),
);
}