-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dart SDK not null safe #13
Comments
Could you @ the dev here please? |
I assume @bennihz or @sashatalalasha? |
Yes it was @sashatalalasha who reported the issue, sorry missed that. |
@sashatalalasha have you been able to use the Dart SDK at all or does this prevent you from embedding it? Also, what version of the SDK have you been using? Unfortunately the tool we use to generate the Dart code generates really bad code that sometimes doesn’t even compile. I have raised an issue in our pipeline on this (ory/sdk#109) and also opened/track several issues in openapi-generator:
I would suggest that when I am back next week we sit down together and try out the different options for Dart generation available and choose the least terrible one 😅 Alternatively we could also use the REST API in raw format for now. What do you think? |
@aeneasr I can't build the app as it constantly throws errors. The SDK version is 2.13.4. Actually, I didn't plan to use the ory client package as Benni is working on a backend that will serve as a mediator between the app and Kratos. Just wanted to check how direct communication works :) Sure we can look for a good code generator together when you're back. Thanks! |
Ah ok! That works also :) If any of you both need help just drop an issue or GitHub discussion here! It would also be great if we could sit together for an hour or so to look at your use of Dart and how we could get our SDKs up to speed as we have flows for native apps :) |
ory/sdk#109 (comment) I want to fix this issue, as it would be great to have a correctly working dart generator. |
Any news? |
I haven't tried using ory with a dart client in a while, but i've successfully used the dart2 generator from the openapi-generator 6.0.x branch. It has null-safety and seems to be working just fine. It is not released yet, so I don't know if ory wants to use it, but I'd say better use (maybe) unstable than outright broken code. |
Oh nice! Yeah, 6.0x is still pretty broken I think but as soon as it becomes stable we wil definitely switch to it. Maybe we can also use individual versions for each SDK type, would require some refactoring though. |
We have updated to the latest versions - not sure if that brings some improvements already? |
FWIW still getting the following 5 months later :( flutter run output
|
What version? |
The 6.x.x version of the generator is now stable and should produce valid code (although not everything ory uses in the specs is supported). |
in my flutter project's pubspec.yaml when I attempted to change manually I got
in my pubspec.yaml I also had I'm going to remove the http (in lieu of using dio which is a dep for openapi) and see how things go! |
Following up now that I am on I still seem to have an error building
code snippetimport 'package:flutter/material.dart';
import 'package:ory_flutter/storage.dart';
import 'package:ory_kratos_client/api.dart';
import 'package:ory_kratos_client/model/session.dart';
import 'package:ory_kratos_client/model/submit_self_service_login_flow_body.dart';
import 'package:ory_kratos_client/model/submit_self_service_logout_flow_without_browser_body.dart';
import 'package:ory_kratos_client/model/submit_self_service_registration_flow_body.dart';
import 'package:ory_kratos_client/model/successful_self_service_login_without_browser.dart';
import 'package:ory_kratos_client/model/successful_self_service_registration_without_browser.dart';
class AuthService {
final backendURL = const String.fromEnvironment('BACKEND');
final kratosClient = OryKratosClient(
basePathOverride: const String.fromEnvironment('KRATOS_API'))
.getV0alpha2Api();
Future<String> intiateRegistrationFlow() async {
var response = await kratosClient
.initializeSelfServiceRegistrationFlowWithoutBrowser();
if (response.statusCode == 200) {
return response.data.id; //return registration flow id
} else if (response.statusCode == 400 || response.statusCode == 500) {
throw Exception(response.statusMessage);
} else {
throw Exception();
}
}
Future<String> initiateLoginFlow() async {
var response =
await kratosClient.initializeSelfServiceLoginFlowWithoutBrowser();
if (response.statusCode == 200) {
return response.data.id; //return login flow id
} else if (response.statusCode == 400 || response.statusCode == 500) {
throw Exception(response.statusMessage);
} else {
throw Exception();
}
}
Future<SuccessfulSelfServiceLoginWithoutBrowser> signIn(
String flowId, String email, String password) async {
var body = SubmitSelfServiceLoginFlowBody((b) => b
..method = "password"
..password = password
..password_identifier = email);
var response = await kratosClient.submitSelfServiceLoginFlow(flowId, body);
if (response.statusCode == 200) {
debugPrint('Signed in: ${response.data}', wrapWidth: 1024);
return response.data;
} else if (response.statusCode == 400 || response.statusCode == 500) {
throw Exception(response.statusMessage);
} else {
throw Exception();
}
}
Future<SuccessfulSelfServiceRegistrationWithoutBrowser> signUp(String flowId,
String email, String password, String phone, String username) async {
var body = SubmitSelfServiceRegistrationFlowBody((b) => b
..method = "password"
..password = password
..traits.email = email
..traits.phone = phone
..traits.username = username);
var response =
await kratosClient.submitSelfServiceRegistrationFlow(flowId, body);
if (response.statusCode == 200) {
debugPrint('Signed up: ${response.data}', wrapWidth: 1024);
return response.data;
} else if (response.statusCode == 400 || response.statusCode == 500) {
throw Exception(response.statusMessage);
} else {
throw Exception();
}
}
Future<Session> getCurrentSession(String token) async {
var response = await kratosClient.toSession(xSessionToken: token);
if (response.statusCode == 200) {
debugPrint('Who am I: ${response.data}', wrapWidth: 1024);
return response.data;
} else if (response.statusCode == 400 || response.statusCode == 500) {
throw Exception(response.statusMessage);
} else {
throw Exception();
}
}
Future<void> signOut() async {
final SecureStorage storage = SecureStorage();
final String? sessionToken = await storage.getToken();
if (sessionToken != null) {
final body = SubmitSelfServiceLogoutFlowWithoutBrowserBody(
(b) => b..session_token = sessionToken,
);
final response =
await kratosClient.submitSelfServiceLogoutFlowWithoutBrowser(body);
if (response.statusCode == 200) {
debugPrint('Signed out: $response', wrapWidth: 1024);
await storage.deleteToken();
return response.data;
} else if (response.statusCode == 400 || response.statusCode == 500) {
throw Exception(response.statusMessage);
} else {
throw Exception();
}
}
}
} |
Looking closer, all files are for dart 2.7 and pub.dev shows failing null safety
|
Hey again @aeneasr! So I think this might have to do with openapi generating using regardless, I'm not sure if Regardless, it seems openapi gen v6.0.0 added support for It would be great if the branched dart-dio or the non-dio dart generator can be used in a (pre)release on pub.dev -- at least until the PR is merged This is a blocking issue for anyone using Flutter 3 (requires >= Dart 2.12 that added null safety) much appreciated 🙏 |
Got it, so shall we use the dart or dart2 generator? |
dart2, but you just set the generator to dart for that. idk it's weird, but that's how it works. |
Ok nice, if anyone is up for the small change, PRs welcomed :) |
@aeneasr PR here ory/sdk#202 |
Thank you - merged! A new release has also been triggered - let's see if it works now :) |
@aeneasr not sure if the release should be live yet, but I'm not seeing it on pub.dev yet https://pub.dev/packages/ory_kratos_client/versions |
fwiw I see https://github.com/ory/sdk/tree/master/clients/client/dart was regenerated and anonymously published here https://pub.dev/packages/ory_client, but not https://github.com/ory/sdk/tree/master/clients/kratos/dart |
Current using the following in my ory_client:
git:
url: https://github.com/ory/sdk.git
path: clients/client/dart Ran into an OpenAPI issue for which I've opened an issue here OpenAPITools/openapi-generator#12914 Other than that the library is now working with null safety |
Sorry for the late reply, please use the meta Ory SDK: https://pub.dev/packages/ory_client/versions The Ory Kratos / Hydra / ... SDKs will only be released when we release a new tag for those. The Ory SDK is being regenerated everytime we make changes to console.ory.sh production! |
Awesome! |
Report from amorevino developer:
Describe the bug
We have an SDK for Dart: https://pub.dev/packages/ory_client
This is created with Dart version 2.0. Dart support for null safety was added in 2.8 (https://dart.dev/null-safety).
This leads to errors when developing Flutter apps.
To Reproduce
https://pub.dev/packages/ory_client/score
Expected behavior
Package is null safe.
Additional context
I do not have experience using the package, so let me know if this is a trivial error or can be worked around easily.
The text was updated successfully, but these errors were encountered: