GoTrueClient constructor

GoTrueClient({
  1. String? url,
  2. Map<String, String>? headers,
  3. bool? autoRefreshToken,
  4. Client? httpClient,
  5. GotrueAsyncStorage? asyncStorage,
  6. AuthFlowType flowType = AuthFlowType.pkce,
})

API client to interact with gotrue server.

url URL of gotrue instance

autoRefreshToken whether to refresh the token automatically or not. Defaults to true.

httpClient custom http client.

asyncStorage local storage to store pkce code verifiers. Required when using the pkce flow.

Set flowType to AuthFlowType.implicit to perform old implicit auth flow.

Implementation

GoTrueClient({
  String? url,
  Map<String, String>? headers,
  bool? autoRefreshToken,
  Client? httpClient,
  GotrueAsyncStorage? asyncStorage,
  AuthFlowType flowType = AuthFlowType.pkce,
})  : _url = url ?? Constants.defaultGotrueUrl,
      _headers = headers ?? {},
      _httpClient = httpClient,
      _asyncStorage = asyncStorage,
      _flowType = flowType {
  _autoRefreshToken = autoRefreshToken ?? true;

  final gotrueUrl = url ?? Constants.defaultGotrueUrl;
  final gotrueHeader = {
    ...Constants.defaultHeaders,
    if (headers != null) ...headers,
  };
  admin = GoTrueAdminApi(
    gotrueUrl,
    headers: gotrueHeader,
    httpClient: httpClient,
  );
  mfa = GoTrueMFAApi(
    client: this,
    fetch: _fetch,
  );
  if (_autoRefreshToken) {
    startAutoRefresh();
  }
}