Session.fromDto constructor

Session.fromDto(
  1. Session session
)

Implementation

factory Session.fromDto(dto.Session session) {
  final token = JwtDecoder.decode(session.token);
  assert(token.containsKey('uid'));

  final refreshToken = JwtDecoder.decode(session.refreshToken);

  return Session(
    token: session.token,
    refreshToken: session.refreshToken,
    created: session.created,
    vars: token.containsKey('vars') ? token['vars'] as Map<String, String>? : {},
    userId: token['uid'] as String,
    expiresAt: DateTime.fromMillisecondsSinceEpoch(
      (token['exp'] as int) * 1000,
    ),
    refreshExpiresAt: DateTime.fromMillisecondsSinceEpoch(
      (refreshToken['exp'] as int) * 1000,
    ),
  );
}