refreshSessionIfExpiring method
Deprecated Refreshes the session if it is expiring soon or expired. Returns the valid session (refreshed or existing).
Implementation
Future<AuthUserSession> refreshSessionIfExpiring(
AuthUserSession existingSession,
) async {
final userId = existingSession.userId;
if (userId.isEmpty) {
logger.error(this, 'Cannot refresh session: userId is unavailable.');
throw AuthException(
AuthenticationErrorCodes.invalidUserIdForSessionRefresh,
);
}
final status = getSessionStatus(existingSession);
if (status == AuthSessionStatus.valid) return existingSession;
try {
logger.info(
this,
'Session for $userId is expiring/expired. Refreshing...',
);
var refreshedSession = await refreshSession(userId);
return refreshedSession;
} catch (e) {
logger.error(this, 'Error refreshing session for $userId', error: e);
rethrow;
}
}