refreshSessionIfNeeded method
Ensures that the session is valid and refreshes it if needed.
The session manager checks whether there's an active DescopeSession and if its session JWT expires within the next 60 seconds. If that's the case then the session is refreshed and persisted before returning.
Note: When using a custom DescopeSessionManager object the exact behavior
here depends on the storage and lifecycle objects.
Implementation
Future<void> refreshSessionIfNeeded() async {
final session = _session;
if (session != null) {
final beforeSession = session.sessionJwt;
final beforeRefresh = session.refreshJwt;
await lifecycle.refreshSessionIfNeeded();
await storage.saveSession(session);
if (beforeSession != session.sessionJwt || beforeRefresh != session.refreshJwt) {
_notifyTokens(session);
}
}
}