Giter Site home page Giter Site logo

Comments (16)

uitlaber avatar uitlaber commented on June 12, 2024 1

After logout

I/flutter (18750): NoSuchMethodError: The getter 'statusCode' was called on null.
I/flutter (18750): Receiver: null
I/flutter (18750): Tried calling: statusCode

photo_2021-01-21_10-24-21

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024 1

I have error after token expired on this line:
final sdk = await Directus(config.API_URL).init(); /auth/refresh Error
and not load public data

My temporary solution: :)

Future<Directus> getSdk() async {
  try {
    return await Directus(config.API_URL).init();
  } catch (e) {
    //Delete all directus__  prefs
    SharedPreferences preferences = await SharedPreferences.getInstance();
    for (String key in preferences.getKeys()) {
      if (key.startsWith('directus__')) {
        preferences.remove(key);
      }
    }
    return await Directus(config.API_URL).init();
  }
}

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024 1

It should be fixed in 0.5.2. Reopen if issue persist after upgrade.

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

Oh anything not work after logout :)

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

remove .init() and working

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024

init() is needed because it initializes the storage, and gets auth data, without it, auth won't work propely.
It's calling /auth/refresh because there is a token that is expired, and it tries to fetch a new one. But it should unlock after getting new token, and finish logging out, so this is definitely a bug

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

my auth.dart

import 'package:directus/directus.dart';
import 'package:meyirim/core/config.dart' as config;

Future<void> logout() async {
  if (await isLoggedIn()) {
    final sdk = await Directus(config.API_URL).init();
    await sdk.auth.logout();
  }
}

Future<void> login(String email, String password) async {
  final sdk = await Directus(config.API_URL).init();
  await sdk.auth.login(email: email, password: password);
}

Future<DirectusResponse<DirectusUser>> register(data) async {
  final sdk = await Directus(config.API_URL).init();
  final createdUser = sdk.users.createOne(DirectusUser.fromJson(data));
  return createdUser;
}

Future<bool> isLoggedIn() async {
  final sdk = await Directus(config.API_URL).init();
  bool result = sdk.auth.isLoggedIn;
  return result;
}

Or how to best way to add global sdk? final sdk = await Directus(config.API_URL).init();

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024

You pass variable like any other, trough constructor, with provider, bloc... if that's what you're asking.
Soon there will be singleton version, you can track progress in #12.
You should initialize sdk only once, then just use that variable:

final sdk = await Directus(url).init();

isLoggedIn() {
return  sdk.auth.isLoggedIn;
}

logout() {
sdk.auth.logout();
}

getData() {
  return sdk.items('data').readMany();
}

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

Maybe i'm on right way

lib/core/auth.dart:7:26: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.12 or higher.
    print(sdk.auth.tokens!.accessToken);

and my token is expired. How clean it ? :)

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

found directus/directus@ff399f9#diff-2e0966802490ef6b64754924c1f0da2807f05359551e77bf115ce40384d56e0f

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024

This library is using null safety, so you have to have Dart version that has enabled nnbd.
It's possible that error from the API is because of the bug that you linked, what version of directus are you using?

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

I used directus version directus/directus:v9.0.0-rc.28 from docker

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024
environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter_svg: ^0.19.2+1
  flutter_swiper: ^1.1.6
  intl: ^0.17.0-nullsafety.2
  cached_network_image: ^2.5.0
  page_transition: ^2.0.1-nullsafety.0
  youtube_player_flutter: ^7.0.0+7
  shared_preferences: ^0.5.12+4
  form_validator: ^0.1.7
  mask_text_input_formatter: ^1.2.1
  dio: ^3.0.10
  directus:
    git:
      url: https://github.com/apstanisic/directus-dart.git
  flutter:
    sdk: flutter
dependency_overrides:
  flutter_inappwebview: ^4.0.0+4

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

not working :(
got error invalid user credentials.

from directus-dart.

uitlaber avatar uitlaber commented on June 12, 2024

I check if add request to url auth/refresh without auth token got same error

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024

Which method is not working? Can you provide a code snippet?
Invalid user credentials is an error returned from the server, so I am not sure if bug is in your code, main repo or in this library.
Does the same happen when you use Postman?

from directus-dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.