Auth constructor
baseUrl
is the Nhost "Backend URL" that can be found on your Nhost
project page.
authStore
(optional) is used to persist authentication tokens
between restarts of your app. If not provided, the tokens will not be
persisted.
refreshToken
(optional) is the result of a previously successful login,
and is used to initialize this client into a logged-in state.
autoLogin
(optional) indicates whether the client should attempt to
login automatically using refreshToken
, or information pulled from
the authStore
(if available).
tokenRefreshInterval
(optional) is the amount of time the client will
wait between refreshing its authentication tokens. If not provided, will
default to a value provided by the server.
httpClientOverride
(optional) can be provided in order to customize the
requests made by the Nhost APIs, which can be useful for proxy
configuration and debugging.
Implementation
Auth({
required String baseUrl,
required UserSession session,
required AuthStore authStore,
String? refreshToken,
bool? autoLogin = true,
Duration? refreshInterval,
required http.Client httpClient,
}) : _apiClient = ApiClient(Uri.parse(baseUrl), httpClient: httpClient),
_session = session,
_authStore = authStore,
_tokenRefreshInterval = refreshInterval,
_refreshTokenLock = false,
_loading = true,
_autoLogin = autoLogin ?? true {
if (_autoLogin) {
_refreshToken(refreshToken);
} else if (refreshToken != null) {
_authStore.setString(refreshTokenClientStorageKey, refreshToken);
} else {
_loading = false;
}
}