NextAuthBloc<T> constructor
NextAuthBloc<T> ({})
Creates a NextAuthBloc with the given configuration.
client - The NextAuth client instance to manage.
refetchInterval - Interval in milliseconds to refetch session. If null, no automatic refetching.
refetchOnWindowFocus - Whether to refetch when app comes to foreground. Defaults to true.
Implementation
NextAuthBloc({
required NextAuthClient<T> client,
int? refetchInterval,
bool refetchOnWindowFocus = true,
}) : _client = client,
_storedRefetchInterval = refetchInterval,
_storedRefetchOnWindowFocus = refetchOnWindowFocus,
super(NextAuthState<T>(status: SessionStatus.initial)) {
_eventsSubscription = _client.eventBus.on<NextAuthEvent>().listen((event) {
if (event is SessionChangedEvent) {
_handleSessionChanged(event.session as T?);
} else if (event is StatusChangedEvent) {
_handleStatusChanged(event.status);
}
});
if (!_isObserverAdded) {
WidgetsBinding.instance.addObserver(this);
_isObserverAdded = true;
}
if (_storedRefetchInterval != null && _storedRefetchInterval > 0) {
_startRefetchTimer(_storedRefetchInterval);
}
// initial state
emit(NextAuthState<T>(session: _client.session, status: _client.status));
}