Giter Site home page Giter Site logo

Comments (5)

ryuuzake avatar ryuuzake commented on June 12, 2024

My idea for a quick fix is by deleting the token to force the user login again to get a new access token and refresh token.

For the exception, I try to remove it because there's no way to handle it when using this package. Dio Interceptor won't rethrow the DirectusError.

Future<AuthResponse?> manuallyRefresh() async {
    ...

    try {
     ...
    } catch (e) {
      currentUser = null;
      tfa = null;
      tokens = null;
      await _emitter.emitAsync('logout', null);
      client.unlock();
      return null;
    }
    ...
}

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024

I'm not sure if we should logout user on error. But it's definitely a bug if we can't handle exception.
manuallyRefresh should not ignore errors, since user can call that method directly, and is a problem if instead of a new access token, he/she was logged out.
I think the problem is with the interceptor, it's his job to handle errors.
What do you think about this? It should properly throw error, but I haven't tested it yet.

// Inside `refreshExpiredTokenInterceptor`
// line 174
   try {
      final response = await manuallyRefresh();
      if (response?.accessToken != null) {
        options.headers['Authorization'] = response!.accessToken;
      } else {
        options.headers.remove('Authorization');
      }
    } catch (e) {
      return handler.reject(DioError(requestOptions: options, error: e));
    }

from directus-dart.

ryuuzake avatar ryuuzake commented on June 12, 2024

When I think about it again, I agree with you. We shouldn't immediately log out the user. I didn't think thoroughly earlier.

Yeah, I think it's a good idea to let manuallyRefresh still throw Exception. But the Exception from it is DirectusError, can it be converted back to DioError? (I don't know about that).
I'll try testing your solution and make some tests around it.

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024

Not currently, but we can add DioError? dioError property, since most of the errors are from http, and assign it when using fromDio constructor. Can you open a PR?

from directus-dart.

apstanisic avatar apstanisic commented on June 12, 2024

Closed in #29

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.