Code Monkey home page Code Monkey logo

nhost-dart's Introduction

# Nhost Packages for Dart & Flutter

Nhost

Nhost

Quickstart   •   Website   •   Docs   •   Blog   •   Twitter   •   Discord


Nhost is an open source Firebase alternative with GraphQL, built with the following things in mind:

  • Open Source
  • GraphQL
  • SQL
  • Great Developer Experience

Nhost consists of open source software:

Architecture of Nhost




Visit https://docs.nhost.io for the complete documentation.

Get Started

Package
nhost_dart Authentication, file storage, and serverless function API clients nhost_dart nhost_dart Pub
nhost_flutter_auth Flutter widgets for exposing Nhost authentication state to your app nhost_flutter_auth nhost_flutter_auth Pub
nhost_flutter_graphql Flutter widgets for providing Nhost GraphQL connections, for use with the graphql_flutter package nhost_flutter_graphql nhost_flutter_auth Pub
nhost_graphql_adapter GraphQL connection setup, for use with the graphql package nhost_graphql_adapter nhost_graphql_adapter Pub
nhost_gql_links (Internal) Library-independent GraphQL link setup nhost_gql_links nhost_gql_links Pub

nhost-dart's People

Contributors

dbarrosop avatar maxschilling avatar mhadaily avatar michalnemec avatar onehassan avatar philipps93 avatar pjindal91 avatar raphaelbarbosaqwerty avatar shyndman avatar sl1mpshady avatar spakanati avatar szilarddoro avatar totzk9 avatar zaqwery 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  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  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  avatar  avatar  avatar

nhost-dart's Issues

Subscription stream error when init (restart is good)

Hello,

I have subscription stream and whenever i init the app and the subscription is on homepage i get error. Whenever i do restart/R reload, its working as intended.

its about gql_websocket_link

 ---------- ERROR ----------
I/flutter (15323): [2022-10-03 17:42:36.705670 | Catcher | INFO] type '(dynamic) => Map<String, dynamic>?' is not a subtype of type '(dynamic) => FutureOr<Map<String, dynamic>>?' of 'function result'
I/flutter (15323): [2022-10-03 17:42:36.705710 | Catcher | INFO]
I/flutter (15323): [2022-10-03 17:42:36.705737 | Catcher | INFO] ------- STACK TRACE -------
I/flutter (15323): [2022-10-03 17:42:36.709501 | Catcher | INFO] #0      WebSocketLink.graphQLSocketMessageDecoder (package:gql_websocket_link/src/link.dart)
package:gql_websocket_link/src/link.dart:1
I/flutter (15323): [2022-10-03 17:42:36.709611 | Catcher | INFO] #1      WebSocketLink._parseSocketMessage
package:gql_websocket_link/src/link.dart:299
I/flutter (15323): [2022-10-03 17:42:36.709974 | Catcher | INFO] #2      WebSocketLink._connect.<anonymous closure>
package:gql_websocket_link/src/link.dart:206
I/flutter (15323): [2022-10-03 17:42:36.710075 | Catcher | INFO] #3      _rootRunUnary (dart:async/zone.dart:1399:47)
I/flutter (15323): [2022-10-03 17:42:36.710255 | Catcher | INFO] #4      _CustomZone.runUnary (dart:async/zone.dart:1300:19)
I/flutter (15323): [2022-10-03 17:42:36.710291 | Catcher | INFO] #5      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
I/flutter (15323): [2022-10-03 17:42:36.710533 | Catcher | INFO] #6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
I/flutter (15323): [2022-10-03 17:42:36.710599 | Catcher | INFO] #7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
I/flutter (15323): [2022-10-03 17:42:36.710629 | Catcher | INFO] #8      _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
I/flutter (15323): [2022-10-03 17:42:36.710806 | Catcher | INFO] #9      _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253:10)
I/flutter (15323): [2022-10-03 17:42:36.710849 | Catcher | INFO] #10     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
I/flutter (15323): [2022-10-03 17:42:36.710888 | Catcher | INFO] #11     _rootRunUnary (dart:async/zone.dart:1399:47)
I/flutter (15323): [2022-10-03 17:42:36.711214 | Catcher | INFO] #12     _CustomZone.runUnary (dart:async/zone.dart:1300:19)
I/flutter (15323): [2022-10-03 17:42:36.711270 | Catcher | INFO] #13     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
I/flutter (15323): [2022-10-03 17:42:36.711300 | Catcher | INFO] #14     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
I/flutter (15323): [2022-10-03 17:42:36.711330 | Catcher | INFO] #15     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
I/flutter (15323): [2022-10-03 17:42:36.711358 | Catcher | INFO] #16     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
I/flutter (15323): [2022-10-03 17:42:36.711390 | Catcher | INFO] #17     _StreamController._add (dart:async/stream_controller.dart:648:7)
I/flutter (15323): [2022-10-03 17:42:36.711417 | Catcher | INFO] #18     _rootRunUnary (dart:async/zone.dart:1399:47)
I/flutter (15323): [2022-10-03 17:42:36.711444 | Catcher | INFO] #19     _CustomZone.runUnary (dart:async/zone.dart:1300:19)
I/flutter (15323): [2022-10-03 17:42:36.711966 | Catcher | INFO] #20     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
I/flutter (15323): [2022-10-03 17:42:36.712069 | Catcher | INFO] #21     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
I/flutter (15323): [2022-10-03 17:42:36.712724 | Catcher | INFO] #22     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
I/flutter (15323): [2022-10-03 17:42:36.712984 | Catcher | INFO] #23     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
I/flutter (15323): [2022-10-03 17:42:36.713037 | Catcher | INFO] #24     _StreamController._add (dart:async/stream_controller.dart:648:7)
I/flutter (15323): [2022-10-03 17:42:36.713066 | Catcher | INFO] #25     _StreamController.add (dart:async/stream_controller.dart:596:5)
I/flutter (15323): [2022-10-03 17:42:36.713103 | Catcher | INFO] #26     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1144:21)
I/flutter (15323): [2022-10-03 17:42:36.713140 | Catcher | INFO] #27     _rootRunUnary (dart:async/zone.dart:1399:47)
I/flutter (15323): [2022-10-03 17:42:36.713168 | Catcher | INFO] #28     _CustomZone.runUnary (dart:async/zone.dart:1300:19)
I/flutter (15323): [2022-10-03 17:42:36.713403 | Catcher | INFO] #29     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
I/flutter (15323): [2022-10-03 17:42:36.715590 | Catcher | INFO] #30     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
I/flutter (15323): [2022-10-03 17:42:36.717215 | Catcher | INFO] #31     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
I/flutter (15323): [2022-10-03 17:42:36.717451 | Catcher | INFO] #32     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
I/flutter (15323): [2022-10-03 17:42:36.718218 | Catcher | INFO] #33     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
I/flutter (15323): [2022-10-03 17:42:36.718592 | Catcher | INFO] #34     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:332:23)
I/flutter (15323): [2022-10-03 17:42:36.719887 | Catcher | INFO] #35     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:226:46)
I/flutter (15323): [2022-10-03 17:42:36.719945 | Catcher | INFO] #36     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
I/flutter (15323): [2022-10-03 17:42:36.719974 | Catcher | INFO] #37     _rootRunUnary (dart:async/zone.dart:1399:47)
I/flutter (15323): [2022-10-03 17:42:36.720001 | Catcher | INFO] #38     _CustomZone.runUnary (dart:async/zone.dart:1300:19)
I/flutter (15323): [2022-10-03 17:42:36.720245 | Catcher | INFO] #39     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
I/flutter (15323): [2022-10-03 17:42:36.720284 | Catcher | INFO] #40     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
I/flutter (15323): [2022-10-03 17:42:36.720510 | Catcher | INFO] #41     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
I/flutter (15323): [2022-10-03 17:42:36.720545 | Catcher | INFO] #42     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
I/flutter (15323): [2022-10-03 17:42:36.720571 | Catcher | INFO] #43     _StreamController._add (dart:async/stream_controller.dart:648:7)
I/flutter (15323): [2022-10-03 17:42:36.720596 | Catcher | INFO] #44     _StreamController.add (dart:async/stream_controller.dart:596:5)
I/flutter (15323): [2022-10-03 17:42:36.720894 | Catcher | INFO] #45     _Socket._onData (dart:io-patch/socket_patch.dart:2324:41)
I/flutter (15323): [2022-10-03 17:42:36.720934 | Catcher | INFO] #46     _rootRunUnary (dart:async/zone.dart:1407:13)
I/flutter (15323): [2022-10-03 17:42:36.720961 | Catcher | INFO] #47     _CustomZone.runUnary (dart:async/zone.dart:1300:19)
I/flutter (15323): [2022-10-03 17:42:36.720987 | Catcher | INFO] #48     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
I/flutter (15323): [2022-10-03 17:42:36.721015 | Catcher | INFO] #49     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
I/flutter (15323): [2022-10-03 17:42:36.721042 | Catcher | INFO] #50     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
I/flutter (15323): [2022-10-03 17:42:36.721067 | Catcher | INFO] #51     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
I/flutter (15323): [2022-10-03 17:42:36.721093 | Catcher | INFO] #52     _StreamController._add (dart:async/stream_controller.dart:648:7)
I/flutter (15323): [2022-10-03 17:42:36.721253 | Catcher | INFO] #53     _StreamController.add (dart:async/stream_controller.dart:596:5)
I/flutter (15323): [2022-10-03 17:42:36.721290 | Catcher | INFO] #54     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1849:33)
I/flutter (15323): [2022-10-03 17:42:36.721317 | Catcher | INFO] #55     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1322:14)
I/flutter (15323): [2022-10-03 17:42:36.721342 | Catcher | INFO] #56     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
I/flutter (15323): [2022-10-03 17:42:36.721367 | Catcher | INFO] #57     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
I/flutter (15323): [2022-10-03 17:42:36.721394 | Catcher | INFO]
I/flutter (15323): [2022-10-03 17:42:36.721420 | Catcher | INFO] ======================================================================

does anybody know whats wrong?

my implementation, which is causing this issue is:

final profile5LastActivitiesProvider =
    StreamProvider.autoDispose.family<UserActivities, GraphQLClient>((ref, graphql) async* {
  final subscription = graphql.subscribe(
    SubscriptionOptions(
      document: gql(GraphQLQuery.subGet5LastActivities),
      fetchPolicy: FetchPolicy.cacheAndNetwork,
    ),
  );

  await for (final value in subscription) {
    yield UserActivities.fromJson(value.data!);
  }
});

E-Mail Verification status as Authentication status

It would be a great help to be able to make use of the e-mail verification status in the auth part as authentication status, or a bool attached to the current user would be a great help for the overall auth process.
Right now it seems there is only a way to read the ApiException message? Adding different status codes than 400 would help as well here in general.
Many thanks!

Passwordless sign in with sms is not enabled

How can I use passwordless sign in with SMS?

Currently it returns 404 not found, with message: Passwordless sign in with sms is not enabled

Version:

  nhost_sdk: ^3.0.1
  nhost_flutter_auth: ^2.0.1

Also, isn't the method inside auth_client.dart supposed to return an AuthResponse? But it returns a void type for now
image

loggin user with auth.login just hangs for ever

So I have setup authentication with nhost-dart following the guideline from this repository:

final nhostClient = NhostClient(baseUrl: authUrl);
...
Widget build(BuildContext context) {
    return NhostAuthProvider(
      auth: nhostClient!.auth, <---
      child: NhostGraphQLProvider(
        nhostClient: nhostClient,
        ...

Now in my login.screen, I call await auth.login(email: __email, password: __password);
This call just takes for ever (2 to 3 minutes) and then crashes the following exception:

image

This behavior is not consistent. I would say it happens in 40% of cases.
Thank you for any help on finding a solution.

GQL subscription is using stale JWT after device idle (iOS)

@MaxSchilling has reported that his graphql client is making a request using a stale JWT after the Android device has been off for some amount of time.

After some research, I suspect that Android Doze suspending timers and network connections. When the app resumes, the websocket notices and begins reconnecting with the old JWT, which happens concurrently with the JWT refresh.

I'm confirming now. If correct, the solution is simple, because the way gql_websocket_link is configured gives us control over socket creation, and that API is async — we can keep it waiting for a JWT refresh.

Connection closed before full header was received

Hi guys,
I'm constantly receiving the following exception and logs after the app refreshes the token a couple times.

"Unhandled Exception: Connection closed before full header was received"
"[nhost] Exception during token refresh"
"Connection closed before full header was received".

After the exception occurs, it seems that the Token stop from being refreshed.

Screen Shot 2022-09-14 at 11 31 53 pm

start_example_server: failed to apply migrations

Hello,

I've got this error message while trying to run the example server on Ubuntu-20.04 in WSL2 (Windows 10):

$ git clone https://github.com/nhost/nhost-dart.git --depth 1

$ cd nhost-dart/tool/

$ ./start_example_server

~/temp/nhost-dart/tool/example_server/functions ~/temp/nhost-dart/tool
~/temp/nhost-dart/tool
~/temp/nhost-dart/tool/example_server ~/temp/nhost-dart/tool

> Initializing Hasura client
> start timeout is set to 10m0s
> Stopping docker compose
> Starting docker compose
> Starting functions
> Starting postgres, graphql-engine containers...
> Waiting for graphql-engine service to be ready
> Waiting for all containers to be up and running
> It takes longer than usual to start your Nhost project. Most likely because of the need to install your npm dependencies. Please wait.


> Processing...
> Ensuring S3 bucket exists
> Checking if migrations need to be applied
> Applying migrations
ERRO skipping applying migrations on database default, encountered:
{
  "code": "postgres-error",
  "error": "query execution failed",
  "internal": {
    "arguments": [],
    "error": {
      "description": null,
      "exec_status": "FatalError",
      "hint": null,
      "message": "must be owner of table files",
      "status_code": "42501"
    },
    "prepared": false,
    "statement": "alter table \"storage\".\"files\"\n  add constraint \"files_uploaded_by_user_id_fkey\"\n  foreign key (\"uploaded_by_user_id\")\n  references \"auth\".\"users\"\n  (\"id\") on update no action on delete cascade;\n"
  },
  "path": "$"
}
FATA[0001] operation failed on : default
> Start took 49.9582051s

> [failed to apply migrations: exit status 1
<nil>] Failed to start services
> Stopping docker compose

If you wanna try WSL2 but is using other operanting system try this free MS Windows VM that comes with WSL2 pre-installed: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
I am using real Windows 10 but I believe the same issue will arise on the VM.

Expose uploadedByUserId on storage

Hello,

Could we have exposure for property uploadedByUserId on files table when we upload an image?
Or it could assign is by itself from JWT (hasura-auth)

Thank you!

Flutter release apk issue

Hi,
I am facing an issue in Nhost flutter application, whenever I am using debug mode apk that time login working properly but in release, app login is not working so can anyone help me?

Exception in subscribtion

After it seems that we have fixed with all subscription errors, yesterday the update of our Donation tracker stopped with this debug output:

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type '(dynamic) => Map<String, dynamic>?' is not a subtype of type '(dynamic) => FutureOr<Map<String, dynamic>>?' of 'function result'
#0      WebSocketLink._parseSocketMessage (package:gql_websocket_link/src/link.dart)
package:gql_websocket_link/src/link.dart:1
#1      WebSocketLink._connect.<anonymous closure>
package:gql_websocket_link/src/link.dart:206
#2      WebSocketLink._connect.<anonymous closure>
package:gql_websocket_link/src/link.dart:201
#3      _rootRunUnary (dart:async/zone.dart:1436:47)
#4      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#5      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#8      _rootRunUnary (dart:async/zone.dart:1436:47)
#9      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#10     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#12     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#13     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#14     _StreamController._add (dart:async/stream_controller.dart:607:7)
#15     _rootRunUnary (dart:async/zone.dart:1436:47)
#16     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#17     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#18     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#19     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#20     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)

404 Error when attempting to register a user with nhost_sdk.

I followed the simple auth example but when I actually run it and try to register a user, I get this error.

ApiException(apiUrl=https://*uniqueID*.nhost.run/auth/register, statusCode=404, responseBody={path: $, error: resource does not exist, code: not-found})

I am assuming it has something to do with me using an Nhost v2 address but I don't see a way of switching to v2 in the SDK.
Thank you in advance.

Add support for Nhost v2

Beta is out the door. Work remaining:

  • Evaluate the need for _loading in AuthService
  • Add missing sign in methods
  • Review backend endpoint by endpoint, ensuring we have support
    • Resend e-mail verification process/e-mail

Is anonymous sign-in supported?

I have searched through the repository but couldn't find any methods related to anonymous sign in. Instead, the User from AuthResponse does return an isAnonymous property. Is it supported?

If it is not supported in the dart SDK, is there any workaround? E.g. Is sign in with refresh token a similar implementation if I have some backene code to generate refresh token for the User?

Thank you very much.

Local stored refresh token not cleared when refresh token has expired

if (authenticationState != AuthenticationState.loggedIn) {

In the case of when refresh token is expired and user is unable to auto login, the code tries to log the user out, however in the above line checks if the user is loggedIn or not. When the auto login in happening the state is not yet loggedId, it is inProgress and due to that, the refreshToken is not cleared from local storage. Moreover _loading flag is never set to false.

Maybe the condition to early return should be modified/removed

Update to latest packages

Hello, could these packages be updated in dependencies? graphql_flutter has 5.1.0 with bindings fix and cannot use it.

  connectivity_plus: ^1.0.1 // there is version 2+
  flutter:
    sdk: flutter
  get: ^4.6.5
  graphql_flutter: ^5.0.0 //5.1.0 breaks
  nhost_flutter_auth: ^2.0.3
  nhost_flutter_graphql: ^2.0.3
  shared_preferences: ^2.0.15
  url_launcher: ^6.1.5

thanks

Add Ferry support

Some users have expressed interest in Ferry support, which is a GraphQL client, built on top of the same gql_exec/gql_link framework that graphql uses.

Subscriptions are failing to update

This was originally reported by @escamoteur via Discord.

After running the software, leaving it for a bit and coming back, subscriptions were no longer updating.

This has been reported as happening on Windows, and macOS.

Deprecated function in `url_launcher`

Problem

launch has been deprecated in favour of launchUrl in 6.1.0.

Because flutter analyze is very strict with info level messages this makes most of the actions fail when building the SDKs.

Return upload progress for fileupload

It would be great to have a callback to retrieve the upload progress of a file, to show it back to users. Firebase offered a subscription method to the upload progress, which was very helpful and user friendly.

Thanks!

Support full set of HTTP verbs when calling serverless functions

Based on the discussion here, it seems there might be a gap in functionality of the SDK or maybe support for GET/DELETE has been removed in new version of nhost. In case, it is supported, then would make sense to have support for GET/DELETE as well in addition to POST. It might even be a breaking change based on the design of the solution hence might make sense to put in the v2 release.

No method to get public file URL from Storage

How to get a public URL if we want to download a file manually without using the functions storage.downloadFile or storage.downloadImage, Something like getPublicUrl in the storage.

At the same time, I tried to use the getPresignedUrl from storage with Nhost running from CLI but I'm keep getting an error ERR_CONNECTION_REFUSED

Thank You!

storage upload issue

Hi, When I run this example(after applying necessary changes), and want to upload a local image to storage on NHost, it fails.

Package:

nhost_sdk: ^3.0.2

Flutter doctor:

[✓] Flutter (Channel stable, 3.0.4, on macOS 12.3.1 21E258 darwin-arm (Rosetta), locale en-DE)
    • Flutter version 3.0.4 at /Users/my_user/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 85684f9300 (3 weeks ago), 2022-06-30 13:22:47 -0700
    • Engine revision 6ba2af10bb
    • Dart version 2.17.5
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/my_user/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.69.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.44.0

[✓] Connected device (2 available)
    • iPhone 13 Pro Max (mobile) • 1269FB42-C790-4240-9148-32FF67DB2276 • ios          • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64 • macOS 12.3.1 21E258 darwin-arm (Rosetta)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Exception:

[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: ApiException: apiUrl=URL/v1/storage/files, statusCode=403, responseBody={error: {message: you are not authorized}}

I checked, when I use the email and password to sign in, I receive a response with a session that all the data are filled. So when I use client.storage.uploadBytes I expect headers be OK.

I also changed the permission of the database for storage_files and add role and gave them permission to insert and select and delete files, but I got internal server error by doing so.

Am I doing something wrong?

NhostGraphQLProvider cache

Hello,

Based on the graphql_flutter, there is setting for cache, is it handled automatically or the setting is just missing?

// We're using HiveStore for persistence,
  // so we need to initialize Hive.
  await initHiveForFlutter();

....

  ValueNotifier<GraphQLClient> client = ValueNotifier(
    GraphQLClient(
      link: link,
      // The default store is the InMemoryStore, which does NOT persist to disk
      cache: GraphQLCache(store: HiveStore()),
    ),
  );

Api exception: invalid-refresh-token

ApiException: apiUrl=https://<backendUrl>.nhost.run/v1/auth/token, statusCode=401, responseBody={status: 401, message: Invalid or expired refresh token, error: invalid-refresh-token}

Facing this issue when the session is automatically refreshed. I have a function which checks auth state and refreshes the token in the background.

  ///
  Future<bool> isUserLoggedIn(BuildContext? context) async {
    log(
      "FILEPATH: lib/src/core/services/auth_service.dart\n",
      name: "isUserLoggedIn()",
    );
    log(
      "Entering function isUserLoggedIn()...\n",
      name: "isUserLoggedIn()",
    );
    log(
      "Reading refreshToken from SharedPreferences...\n",
      name: "isUserLoggedIn()",
    );

    final String? storedRefreshToken = await _prefs.then(
      (SharedPreferences value) => value.getString("refresh_token"),
    );

    if (storedRefreshToken == null) {
      log(
        "refreshToken not found from SharedPreferences...\n",
        name: "isUserLoggedIn()",
      );
      isAuthenticated = false;
      //   notifyListeners();
      return false;
    } else if (!isAuthenticated) {
      try {
        log(
          "refreshToken found from SharedPreferences attempting to signInWithRefreshToken...\n",
          name: "isUserLoggedIn()",
        );
        log(
          "Calling:  nhostClient.auth.signInWithRefreshToken($storedRefreshToken)\n",
          name: "isUserLoggedIn()",
        );

        final AuthResponse response =
            await nhostClient.auth.signInWithRefreshToken(storedRefreshToken);

        log(
          "AuthResponse success; userId: ${response.user?.id}\n",
          name: "isUserLoggedIn()",
        );

        await _prefs.then(
          (SharedPreferences value) => value.setString(
            "refresh_token",
            response.session!.refreshToken ?? "",
          ),
          // ignore: always_specify_types
          onError: (e, s) {
            log(e.toString(), error: e);
            log(s.toString(), error: s);
          },
        );

        log(
          "SharedPreferences.write; refreshToken: ${response.session!.refreshToken}\n",
          name: "isUserLoggedIn()",
        );

        accessToken = response.session!.accessToken!;
        isAuthenticated = true;
        userId = response.session!.user!.id;
        notifyListeners();
      } on ApiException catch (e, s) {
        if (context != null) {
          context
              .read<SharedService>()
              .showToast(message: e.body["message"].toString());
        }
        log("FILEPATH: lib/src/core/services/auth_service.dart 184:49");
        log(
          "ApiException ERROR on isUserLoggedIn: \n${e.body}\n - stack: $s",
          name: "isUserLoggedIn()",
          error: e.statusCode,
          stackTrace: s,
        );
      } catch (e, s) {
        if (context != null) {
          context.read<SharedService>().showToast(message: e.toString());
        }
        log("FILEPATH: lib/src/core/services/auth_service.dart 194:49");
        log(e.toString());
        log(
          "ERROR on isUserLoggedIn: $e - stack: $s",
          name: "isUserLoggedIn()",
          error: e,
          stackTrace: s,
        );
      }
    }
    return isAuthenticated;
  }

upgrade nhost lints dependency

Hi guys, could you please upgrade the lints dependency from nhost_sdk?
I'm trying to use the nhost_sdk ^3.0.2 and it's not compatible with the most recent versions of flutter_lints and lints.

Because no versions of flutter_lints match >2.0.1 <3.0.0 and flutter_lints 2.0.1 depends on lints ^2.0.0, flutter_lints ^2.0.1 requires lints ^2.0.0.
And because nhost_sdk >=2.0.2 depends on lints ^1.0.0, flutter_lints ^2.0.1 is incompatible with nhost_sdk >=2.0.2.

thank you

Native Auth Support

Hi,
will it support native auth flow and not via web view for social login providers?

StreamSubscriptions triggering all events on auth token refresh

Hey guys,

I observed that when the service token changes (NHostClient addTokenChangedCallback is triggered), all my subscription streams attached to Hasura produce the same data again since the app started listening to them.

Is that the expected behaviour?

Would be a security breach to not refresh the token every minute but once every couple of hours as a way around? What's the drawback?

Any suggestions?

Currenly utilising nhost_sdk: ^3.0.4 and nhost_graphql_adapter: ^2.0.3

Thank you

resetPassword: The value of "options.redirectTo" is not allowed

I'm getting this exception while trying to reset the password of a user:

E/flutter (12035): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ApiException: apiUrl=https://jixoaoumojenusgmwtfd.nhost.run/v1/auth/user/password/reset, statusCode=400, responseBody={status: 400, message: The value of "options.redirectTo" is not allowed., error: invalid-request}
E/flutter (12035): #0      ApiClient._handleResponse (package:nhost_sdk/src/api/api_client.dart:281:7)
E/flutter (12035): #1      ApiClient.send (package:nhost_sdk/src/api/api_client.dart:240:12)
E/flutter (12035): <asynchronous suspension>
E/flutter (12035): #2      AuthClient.resetPassword (package:nhost_sdk/src/auth_client.dart:450:5)
E/flutter (12035): <asynchronous suspension>
E/flutter (12035): #3      LoginEmailForgotController.submit (package:app/pages/login_email_forgot.dart:23:5)
E/flutter (12035): <asynchronous suspension>
E/flutter (12035):

The code (at trace # 3) is the following submit method in my controller:

  Future<void> submit() async {
    NHostController nhc = Get.find();
    await nhc.client.auth.resetPassword(
        email: emailCtrl.value.text.trim(),
        redirectTo: '/app/login_email_forgot_change');
  }

I think the code already complies with the usage of redirectTo as specified in the JavaScript reference.

But for some reason it's still failing. The logs at NHost dashboard are very limited and not quite useful:

2022-12-22 16:04:27 | hasura-auth | {"latencyInNs":4000000,"level":"info","message":"POST /user/password/reset 400 4ms","method":"POST","statusCode":400,"url":"/user/password/reset"}

2022-12-22 16:03:25 | hasura-auth | {"latencyInNs":16000000,"level":"info","message":"POST /user/password/reset 400 16ms","method":"POST","statusCode":400,"url":"/user/password/reset"}

Any pointers?

CI is failing

It appears that an upgrade of pana (a transient dep) from 0.17.0 to 0.17.1 has created problems. Investigating.

oauth_providers_example.dart: example needs to be updated

The example's comments give wrong instructions regarding the configuration of NHost's OAuth callbacks:

At line 10 it reads:

/// Success redirect URL: `nhost-example://oauth.login.success`.
/// Failure redirect URL: `nhost-example://oauth.login.failure`.

wheareas only one callback URL can be set on GitHub settings and no URL can be set on NHost's GitHub provider configuration.

Also at line 23, the sign in URL is wrong. It should look like:

/// Fill in this value with the backend URL found on your Nhost project page.
const nhostGithubSignInUrl = '$nhostUrl/v1/auth/signin/provider/github';

JWTExpired errors after leaving the app open for a short while

I'm seeing JWTExpired errors when leaving the app open for a bit, suggesting the token refresh is not working correctly. It's a dealbreaker right now in terms of being able to use nhost in production because after a fairly short amount of time the app breaks because all queries/mutations/subscriptions stop executing and you have to refresh the entire app.

Similar to #21 but the errors I'm seeing are for any type of operation, not just subscriptions, so I don't think it's purely a websocket problem. I also saw nhost/nhost#405 and it seems that the JS library had a very similar issue, so it might be that the Dart/Flutter library needs to implement the same logic to make sure that the app does not allow the JWT to expire.

Apple login support?

Hi. I really love your platform, few points here:

  1. On iOS if you include any oauth in your app, it must support apple auth otherwise the app will be rejected.
  2. What is the advantage of using webview url redirect over fetching the oauth access token natively like this? https://pub.dev/packages/google_sign_in Can this be supported in nhost sdk?
  3. Suggestion - I think there is a win in copying the package API design from firebase, as it becomes the de-facto standart in flutter community for implementing auth. People will have less headache migrating to this platform.

Migrate from debugPrint to using logging package

I'm finding that adding and removing state logging while debugging is resulting in repeated work, so I'd like to introduce detailed trace/info/error logs, that can be turned off or on easily (off by default).

logging appears to be a solid logging framework to attach to. It's simple, doesn't change often, and is already used by plenty of packages.

Error propagation during refresh instead of silent failure

Hi, previously it was discussed here that there is a design flaw in the library where it doesn't propagate the errors back to the client when exception happens during refresh of token. I am wondering if migration to version 2 is a good opportunity to do that as it might be a breaking change depending on how the library is redesigned.

Example here, the exceptions are logged and not propagated to the client hence the client is eternally in AuthenticationState.inprogress state. In my previous project i overcame this limitation but by putting a time out on the application side but I think this should be fixed in the library.

If the resdesign of the library is out of scope then one small enhancement we can make is just like we allow clients to add state change handlers, we can allow clients to register error callback handler, which can be called when the above exception happens with appropriate error message. Although its not a full proof solution since the application might not register with the error callback, it will atleast provide a way for the application to know that an exception happened underneath.

Imo correct way would be to decouple initialization of Auth instance with refresh from here. I think we should let the client call a function refreshToken explicitly after they have initialized NhostClient and by extension Auth object. That way we can simply throw the exception from refreshToken function and client can handle it on their side.

What do you think @shyndman? I am happy to work on this fix once we decide which approach to take.

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.