Giter Club home page Giter Club logo

Comments (6)

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024 1

I've just tested it locally with the Dart cli and I'm not able to reproduce it (PocketBase Dart SDK v0.14.1 and PocketBase executable v0.17.7).

// example.dart
import "dart:io";

import "package:pocketbase/pocketbase.dart";

void main() {
  final pb = PocketBase("http://127.0.0.1:8090");

  pb.collection("users").authWithOAuth2("discord", (url) async {
    // replace with "explorer" for windows or "open" for mac
    Process.run("xdg-open", [url.toString()]);
  }).then((result) {
    print("Result: $result");
  }).catchError((dynamic err) {
    print("Error: $err");
  });
}

Run with dart run example.dart (tested on Linux, for other platforms change the command).

The above is running a shell command to fire a browser window from the terminal but it should be the same with url_launcher or any other package (the goal is to open the signin url from the callback in a browser window).

I suspect in your case you are testing in Flutter web, where as mentioned earlier, streamed responses are not supported out of the box and you have to provide your own http client as shown in https://github.com/pocketbase/dart-sdk#limitations.

If that's not the case, please provide more details on what platform your code is running and the versions of the PocketBase executable and SDK, and I'll investigate it further.

from dart-sdk.

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024

Where is the Dart code running, aka. what platform do you target?

If it is Flutter Web, the realtime events are not supported there (the "all-in-one" authWithOAuth2() call relies on a realtime subscription) and you have to provide a custom http client (see https://github.com/pocketbase/dart-sdk#limitations).

from dart-sdk.

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024

Side-note: If you use Fly, also keep in mind that the last time I checked their free service had 60s limit for how long a connection can remain open, which is not an issue with the regular realtime subscriptions as there is autoreconnect, but with the "all-in-one" OAuth2 call that means that the OAuth2 sign process must happen under 60s, otherwise you'll get an error for "missing/invalid client id" or similar.

from dart-sdk.

breezko avatar breezko commented on June 18, 2024

Thanks for the hint. Indeed I am using flutter. This issue was resolved by httpClientFactory: kIsWeb ? () => FetchClient(mode: RequestMode.cors) : null,

However the callback gives me an error:

{"code":404,"message":"Missing or invalid OAuth2 subscription client.","data":{}}

So basically oauth doesnt work on flutter web with pocketbase dart sdk?

Thats my code:

final pb = PocketBase('https://someurl.fly.dev', httpClientFactory: kIsWeb ? () => FetchClient(mode: RequestMode.cors) : null,);
          print("GO");
        final authData2 =
            await pb.collection('users').authWithOAuth2('discord', (url) async {
              print(url);
          await launchUrl(url);
        });

from dart-sdk.

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024

See the note in #47 (comment). It could be also an issue with the fetch_client compatibility as I haven't tested it thoroughly.

If you are using Flutter Web just for dev preview/tests, I'd recommend using Flutter Desktop instead.

from dart-sdk.

breezko avatar breezko commented on June 18, 2024

Issue was resolved. Provider redirect uri was incorrect.
Works for Flutter WEB:


final pb = PocketBase(
                'https://url.fly.dev',
                httpClientFactory: () => FetchClient(mode: RequestMode.cors),
              );
              final authData = await pb
                  .collection('users')
                  .authWithOAuth2('discord', (url) async {
                await launchUrl(url);
              });

              print(pb.authStore.isValid);
              print(pb.authStore.token);
              print(pb.authStore.model.id);
              ```

from dart-sdk.

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.