clerk_auth 0.0.13-beta
clerk_auth: ^0.0.13-beta copied to clipboard
Package that will allow you to authenticate and use Clerk from Dart code.
Official Clerk Dart SDK (Beta) #
⚠️ The Clerk Flutter SDK is in Beta ⚠️ #
❗️ Breaking changes should be expected until the first stable release (1.0.0) ❗️
Clerk helps developers build user management. We provide streamlined user experiences for your users to sign up, sign in, and manage their profile from your Dart code.
Requirements #
- Dart >= 3.6.2
Example Usage #
To use this package you will need to go to your Clerk Dashboard create an application and copy the public and publishable API keys into your project.
import 'dart:io';
import 'package:clerk_auth/clerk_auth.dart';
Future<void> main() async {
final auth = Auth(
config: const AuthConfig(
publishableKey: '<YOUR-PUBLISHABLE-KEY>',
),
persistor: DefaultPersistor(
getCacheDirectory: () => Directory.current,
),
// To enable running of the example in e.g. Flutter environments where
// [Directory.current] causes problems, use the `clerk_flutter` package and
// use:
// persistor: DefaultCachingPersistor(
// getCacheDirectory: getApplicationDocumentsDirectory,
// )
// Which will use the correct directory for the platform your Flutter app
// is running on. You can also implement a bespoke [Persistor] specific
// to your applications storage mechanism,
//
// or replace the above line with...
// persistor: Persistor.none,
);
await auth.initialize();
await auth.attemptSignIn(
strategy: Strategy.password,
identifier: '<USER-EMAIL>',
password: '<PASSWORD>',
);
print('Signed in as ${auth.user}');
await auth.signOut();
auth.terminate();
}
For more details see Clerk Auth object
Session Token Polling #
By default, ClerkAuth will regularly poll for session tokens, providing them into the app
via the sessionTokenStream. In line with other Clerk SDKs (and if organizations are enabled) the stream
of session tokens will be augmented with data from the Organization most recently activated.
If you do not wish for session tokens to be polled in this way, the behaviour can be disabled
through the config object when creating your Auth object:
final auth = Auth(
config: const AuthConfig(
publishableKey: '<YOUR-PUBLISHABLE-KEY>',
sessionTokenPolling: false,
...
),
...
);
Note re: v0.0.12-beta and previous #
Note that the behaviour described above has been introduced in v0.0.13-beta. Prior versions defaulted to
polling off, enabling it via a SessionTokenPollMode object in the config. This object has been deprecated in
v0.0.13-beta: it is no longer used, and will be deleted in a future version. If you are using it, or relying on
the system defaulting to no polling, please review your code.
License #
This SDK is licensed under the MIT license found in the LICENSE file.