Code Monkey home page Code Monkey logo

appwrite_auth_kit's Introduction

Namaste, Damodar here from Nepal! ๐Ÿ‘‹

I'm an author, mentor, trainer, and tech consultant. I'm currently working as a Software Engineer at Appwrite.

๐ŸŽ‰ Exciting News! ๐ŸŽ‰

๐Ÿ‘ท Check out what I'm currently working on

Tech Stack

Flutter, Firebase, Appwrite, NestJs, ReactJS, Laravel, Dart, HTML, CSS, JS, Svelte

Connect with me:

website blog youtube twitter linkedin

๐Ÿ“บ Latest YouTube Videos

๐Ÿ“• Latest Blog Posts

appwrite_auth_kit's People

Contributors

faisalmohammadi avatar javibonilla avatar lohanidamodar avatar sbergmair avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

appwrite_auth_kit's Issues

Handle Authentication Errors Effectively

I'm facing challenges in handling authentication errors. Specifically, I'm unable to find a clear and robust way to deal with errors such as wrong passwords, invalid email addresses, etc.

I have noticed that there is a nullable string named context.authNotifier.error that seems to be related to authentication errors. However, the documentation does not provide sufficient information on the possible error messages that can be encountered. Even if I had this information, relying on string validation for error handling is not considered a best practice.

I propose introducing a new enum variable, let's call it AuthError, that enumerates possible authentication error types. This would make error handling more structured and easier to manage. Developers can then listen to this enum variable and display appropriate error messages in the user interface.

Unhandled Exception: type 'Null' is not a subtype of type 'List<dynamic>'

I get the following error with the new Version 0.9.0

Unhandled Exception: type 'Null' is not a subtype of type 'List'

The error gets thrown in file lib/src/accounts_provider.dart, when the Appwrite SDK calls models.User.fromMap(res.data); to get the current session. When no User is logged in, the appwrite sdk throws an Null exception, which is unhandled (I think this is the Problem, but I`m not sure).

With Version 0.8.0 it works perfectly

StackTrace:

#0      new User.fromMap (package:appwrite/src/models/user.dart:87:18)
#1      Account.get (package:appwrite/services/account.dart:23:24)
<asynchronous suspension>
#2      AuthNotifier._getUser (package:appwrite_auth_kit/src/accounts_provider.dart:65:15)
<asynchronous suspension>

User redirected back to the login page after no internet connection

When their is no internet connection the state of the Auth changes to the unauthenticated and the user redirects to the login page
After making the internet available back it goes directly to the main page and the auth state is then authenticated.
It should stay authenticated or at least should stay in main page after no internet connection.
from the UX perspective it looks not good that after no internet it redirects to the Login Page, but at the back its already authenticated.

My implementation of Auth

class MainWidget extends StatelessWidget {
  const MainWidget({super.key});

  @override
  Widget build(BuildContext context) {
    final authNotifier = context.authNotifier;
    Widget widget;
    switch (authNotifier.status) {
      case AuthStatus.authenticated:
        widget = const FeedPage();
        break;
      case AuthStatus.unauthenticated:
      case AuthStatus.authenticating:
        widget = const LoginPage();
        break;
      case AuthStatus.uninitialized:
        widget = const SplashScreenWidget();
        break;
      default:
        widget = const SplashScreenWidget();
        break;
    }
    return widget;
  }
}

Get `$id` without context

Is there a way to get the $id of the current user in initState, since I can't use context there?

Here is an example:

@override
void initState() {
    super.initState();
    boatsStream = DB.boat.streamBoats(uid); // Initialize the stream
}

I somehow need to get the users id here. But it's not only initState functions where I need to get the $id without context, for example in the toMap function of some of my models I also need it.

I'm getting error when I was trying to use package with GetX package

======== Exception caught by widgets library =======================================================
The following assertion was thrown building MainScreen(dirty, dependencies: [FlAppwriteAccountKit]):
setState() or markNeedsBuild() called during build.

This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: Overlay-[LabeledGlobalKey<OverlayState>#c5b77]
  state: OverlayState#cee5b(entries: [OverlayEntry#62e83(opaque: true; maintainState: false), OverlayEntry#a96c4(opaque: false; maintainState: true), OverlayEntry#82e01(opaque: false; maintainState: false), OverlayEntry#fdc08(opaque: false; maintainState: true)])
The widget which was currently being built when the offending call was made was: MainScreen
  dirty
  dependencies: [FlAppwriteAccountKit]
The relevant error-causing widget was: 
  MainScreen MainScreen:file:///Users/ruslan/StudioProjects/wizard_game/lib/main.dart:20:15
When the exception was thrown, this was the stack: 
#0      Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:4424:11)
#1      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4439:6)
#2      State.setState (package:flutter/src/widgets/framework.dart:1141:15)
#3      OverlayState.rearrange (package:flutter/src/widgets/overlay.dart:444:5)
#4      NavigatorState._flushHistoryUpdates (package:flutter/src/widgets/navigator.dart:3950:16)
#5      NavigatorState._pushEntry (package:flutter/src/widgets/navigator.dart:4438:5)
#6      NavigatorState.push (package:flutter/src/widgets/navigator.dart:4366:5)
#7      GetNavigation.to (package:get/get_navigation/src/extension_navigation.dart:522:37)
#8      MainScreen.build (package:wizard_game/app/modules/login/views/main_screen.dart:23:13)
#9      StatelessElement.build (package:flutter/src/widgets/framework.dart:4827:28)
#10     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4754:15)
#11     Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
#12     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4735:5)
#13     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4729:5)
...     Normal element mounting (171 frames)
#184    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3790:14)
#185    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6422:36)
#186    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6433:32)
...     Normal element mounting (403 frames)
#589    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3790:14)
#590    Element.updateChild (package:flutter/src/widgets/framework.dart:3540:18)
#591    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1198:16)
#592    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1167:5)
#593    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1112:18)
#594    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2600:19)
#595    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1111:13)
#596    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:944:7)
#597    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:924:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
====================================================================================================
D/eglCodecCommon(28630): setVertexArrayObject: set vao to 0 (0) 1 0
W/OpenGLRenderer(28630): dequeueBuffer failed, error = -110; switching to fallback
W/Gralloc3(28630): allocator 3.x is not supported
W/OpenGLRenderer(28630): reserveNext failed, error = -2147483648 (Unknown error -2147483648)
D/EGL_emulation(28630): eglMakeCurrent: 0xd541a420: ver 3 0 (tinfo 0xd540fd30)
E/flutter (28630): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2845 pos 18: '!navigator._debugLocked': is not true.
E/flutter (28630): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (28630): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter (28630): #2      _RouteEntry.handlePush.<anonymous closure> (package:flutter/src/widgets/navigator.dart:2845:18)
E/flutter (28630): #3      TickerFuture.whenCompleteOrCancel.thunk (package:flutter/src/scheduler/ticker.dart:407:15)
E/flutter (28630): #4      _rootRunUnary (dart:async/zone.dart:1434:47)
E/flutter (28630): #5      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter (28630): <asynchronous suspension>
E/flutter (28630): #6      TickerFuture.whenCompleteOrCancel.thunk (package:flutter/src/scheduler/ticker.dart:406:5)
E/flutter (28630): <asynchronous suspension>
E/flutter (28630): 
I/ght.wizard_gam(28630): WaitForGcToComplete blocked HeapTrim on None for 26.313ms

======== Exception caught by widgets library =======================================================
The following assertion was thrown building MainScreen(dirty, dependencies: [FlAppwriteAccountKit]):
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4429 pos 12: '!_debugLocked': is not true.



Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md


The relevant error-causing widget was: 
  MainScreen MainScreen:file:///Users/ruslan/StudioProjects/wizard_game/lib/main.dart:20:15
When the exception was thrown, this was the stack: 
#2      NavigatorState._pushEntry (package:flutter/src/widgets/navigator.dart:4429:12)
#3      NavigatorState.push (package:flutter/src/widgets/navigator.dart:4366:5)
#4      GetNavigation.to (package:get/get_navigation/src/extension_navigation.dart:522:37)
#5      MainScreen.build (package:wizard_game/app/modules/login/views/main_screen.dart:15:13)
#6      StatelessElement.build (package:flutter/src/widgets/framework.dart:4827:28)
#7      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4754:15)
#8      Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
#9      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2659:19)
#10     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#11     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
#12     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
#13     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1081:9)
#14     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:995:5)
#18     _invoke (dart:ui/hooks.dart:151:10)
#19     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#20     _drawFrame (dart:ui/hooks.dart:115:31)
(elided 5 frames from class _AssertionError and dart:async)
====================================================================================================

๐Ÿž : `Error: Expected a value of type 'Map<String, dynamic>', but got one of type 'String'` Error

Full error while runnig my flutter authkit app

Launching lib/main.dart on Chrome in debug mode...
package:teletest/main.dart:1
This app is linked to the debug service: ws://127.0.0.1:41535/g1YH8UNqwtA=/ws
Debug service listening on ws://127.0.0.1:41535/g1YH8UNqwtA=/ws
๐Ÿ’ช Running with sound null safety ๐Ÿ’ช
Connecting to VM Service at ws://127.0.0.1:41535/g1YH8UNqwtA=/ws
Flutter Web Bootstrap: Programmatic
Failed to load font Roboto at https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf
TypeError: Failed to fetch
Error: Expected a value of type 'Map<String, dynamic>', but got one of type 'String'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49      throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 99:3        castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 452:10  cast
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart 635:14     as_C
packages/appwrite/services/account.dart 23:27                                     get
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                <fn>
dart-sdk/lib/async/zone.dart 1653:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5                                         [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7                                         callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                                  _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15               <fn>

my pubspec.yaml :

name: teletest
description: A new Flutter project.
version: 1.0.0+1

environment:
  sdk: '>=2.18.5 <3.0.0'

dependencies:
  flutter:
    sdk: flutter 
  appwrite_auth_kit: 0.7.0
  random_string: ^2.3.1

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

Auth via phone

Can you briefly explain how to use createPhoneSession? More precisely, how to get a token and then insert it into updatePhoneSession? After all, the createPhoneSession method returns only true or false.

createSession directly sets the user as Authenticated

This can be the expected behavior in some cases but in others it is required that the user's email in verified, in such cases the createSession method must be called to check the emailVerification property.

The createSession method could be called in these cases:

  • Login (check email is verified).
  • Singup (send verification email).
  • Resend verification email.

I don't know what it is the best way to tackle this, but I suggest to consider these options:

  • Have two different AuthStatus states: authenticatedVerified and authenticatedNotVerified instead of authenticated.
  • Include and optional parameter notifyListeners = true in createSession and deleteSession, so these methods can be used for signing up and resending verification emails.

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.