Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class Environment with InformativeToStringMixin {
].contains(i),
);

/// [List] of available social connections i.e. oAuth sign in possibilites
List<SocialConnection> get socialConnections => user.socialSettings.values
.where((s) => oauthStrategies.contains(s.strategy))
.toList(growable: false);

/// Do we have social connections?
bool get hasSocialConnections => socialConnections.isNotEmpty;

/// Do we have identification strategies?
bool get hasIdentificationStrategies => identificationStrategies.isNotEmpty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class OrganizationSettings with InformativeToStringMixin {
this.actions = OrganizationActions.empty,
this.domains = DomainSettings.empty,
this.isEnabled = false,
this.forceOrganizationSelection = false,
});

/// max allowed memberships
Expand All @@ -32,9 +33,15 @@ class OrganizationSettings with InformativeToStringMixin {
/// organization actions
final OrganizationActions actions;

/// force organization selection
final bool forceOrganizationSelection;

/// empty [OrganizationSettings]
static const empty = OrganizationSettings();

/// do we allow personal orgs?
bool get allowsPersonalOrgs => forceOrganizationSelection == false;

/// is enabled?
@JsonKey(name: 'enabled')
final bool isEnabled;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ClerkSignInExample extends StatelessWidget {
padding: const EdgeInsets.all(16),
child: ClerkAuthBuilder(
signedInBuilder: (context, authState) {
if (authState.env.organization.isEnabled == false) {
if (authState.env.organization.isEnabled == false ||
authState.user!.hasOrganizations == false) {
return const ClerkUserButton();
}
return const _UserAndOrgTabs();
Expand Down
5 changes: 5 additions & 0 deletions packages/clerk_flutter/l10n/en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"connectedAccounts": "Connected accounts",
"cont": "Continue",
"createOrganization": "Create organization",
"developmentMode": "Development mode",
"didntReceiveCode": "Didn't receive the code?",
"domainName": "Domain name",
"dontHaveAnAccount": "Don’t have an account?",
Expand All @@ -78,6 +79,7 @@
}
},
"enterTheCodeSentToYou": "Enter the code sent to you",
"enterYourOrganizationDetailsToContinue": "Enter your organization details to continue",
"expired": "expired",
"failed": "failed",
"firstName": "first name",
Expand Down Expand Up @@ -123,6 +125,7 @@
"logo": "Logo",
"manualInvitation": "Manual invitation",
"missingRequirements": "missing requirements",
"myOrganization": "My Organization",
"name": "Name",
"needsFirstFactor": "needs first factor",
"needsIdentifier": "needs identifier",
Expand Down Expand Up @@ -209,6 +212,7 @@
"resetPassword": "Reset password and sign in",
"selectAccount": "Select the account with which you wish to continue",
"sendMeTheCode": "Send me the reset code",
"setUpYourOrganization": "Set up your organization",
"signIn": "Sign in",
"signInByClickingALinkSentToYouByEmail": "Sign in by clicking a link sent to you by email",
"signInByEnteringACodeSentToYouByEmail": "Sign in by entering a code sent to you by email",
Expand Down Expand Up @@ -249,6 +253,7 @@
}
}
},
"slug": "Slug",
"slugUrl": "Slug URL",
"switchTo": "Switch to",
"termsAndConditions": "Terms & Conditions",
Expand Down
30 changes: 30 additions & 0 deletions packages/clerk_flutter/lib/generated/clerk_sdk_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ abstract class ClerkSdkLocalizations {
/// **'Create organization'**
String get createOrganization;

/// No description provided for @developmentMode.
///
/// In en, this message translates to:
/// **'Development mode'**
String get developmentMode;

/// No description provided for @didntReceiveCode.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -336,6 +342,12 @@ abstract class ClerkSdkLocalizations {
/// **'Enter the code sent to you'**
String get enterTheCodeSentToYou;

/// No description provided for @enterYourOrganizationDetailsToContinue.
///
/// In en, this message translates to:
/// **'Enter your organization details to continue'**
String get enterYourOrganizationDetailsToContinue;

/// No description provided for @expired.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -438,6 +450,12 @@ abstract class ClerkSdkLocalizations {
/// **'missing requirements'**
String get missingRequirements;

/// No description provided for @myOrganization.
///
/// In en, this message translates to:
/// **'My Organization'**
String get myOrganization;

/// No description provided for @name.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -702,6 +720,12 @@ abstract class ClerkSdkLocalizations {
/// **'Send me the reset code'**
String get sendMeTheCode;

/// No description provided for @setUpYourOrganization.
///
/// In en, this message translates to:
/// **'Set up your organization'**
String get setUpYourOrganization;

/// No description provided for @signIn.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -774,6 +798,12 @@ abstract class ClerkSdkLocalizations {
/// **'Sign up to {name}'**
String signUpTo(String name);

/// No description provided for @slug.
///
/// In en, this message translates to:
/// **'Slug'**
String get slug;

/// No description provided for @slugUrl.
///
/// In en, this message translates to:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
@override
String get createOrganization => 'Create organization';

@override
String get developmentMode => 'Development mode';

@override
String get didntReceiveCode => 'Didn\'t receive the code?';

Expand Down Expand Up @@ -140,6 +143,10 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
@override
String get enterTheCodeSentToYou => 'Enter the code sent to you';

@override
String get enterYourOrganizationDetailsToContinue =>
'Enter your organization details to continue';

@override
String get expired => 'expired';

Expand Down Expand Up @@ -199,6 +206,9 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
@override
String get missingRequirements => 'missing requirements';

@override
String get myOrganization => 'My Organization';

@override
String get name => 'Name';

Expand Down Expand Up @@ -349,6 +359,9 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
@override
String get sendMeTheCode => 'Send me the reset code';

@override
String get setUpYourOrganization => 'Set up your organization';

@override
String get signIn => 'Sign in';

Expand Down Expand Up @@ -396,6 +409,9 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
return 'Sign up to $name';
}

@override
String get slug => 'Slug';

@override
String get slugUrl => 'Slug URL';

Expand Down
17 changes: 17 additions & 0 deletions packages/clerk_flutter/lib/src/utils/clerk_sdk_grammar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ abstract class ClerkSdkGrammar {
/// Current locale can be derived from the [context]
///
String toSentence(String item);

/// Return a slug from a given name
///
/// This needs to return a string that is lowercase, and contains only
/// alphanumeric Latin/Arabic characters and hyphens (which typically replace
/// other characters). Languages that do not use Latin/Arabic characters
/// beware!
///
String toSlug(String name);
}

/// A [ClerkSdkGrammar] default implementation, using English language
Expand Down Expand Up @@ -121,4 +130,12 @@ class ClerkSdkGrammarEn implements ClerkSdkGrammar {
@override
String toSentence(String item) =>
item.isNotEmpty ? item[0].toUpperCase() + item.substring(1) : '';

static final _nonAlphaNum = RegExp(r'[^a-z0-9]+');

/// To make a name into a slug in English we lowercase it, remove
/// non-alphanumerics, and replace whitespace with hyphens
@override
String toSlug(String name) =>
name.toLowerCase().replaceAll(_nonAlphaNum, '-');
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class _ClerkAuthenticationState extends State<ClerkAuthentication>
],
),
),
Closeable(
closed: _state.isSigningIn == false,
Openable(
open: _state.isSigningIn,
child: const ClerkSignInPanel(),
),
Closeable(
closed: _state.isSigningUp == false,
Openable(
open: _state.isSigningUp,
child: const ClerkSignUpPanel(),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,33 @@ class _ClerkOAuthPanelState extends State<ClerkOAuthPanel>
with ClerkTelemetryStateMixin {
@override
Widget build(BuildContext context) {
final authState = ClerkAuth.of(context);
if (authState.isNotAvailable) {
return emptyWidget;
}
return ClerkAuthBuilder(
builder: (context, authState) {
if (authState.isNotAvailable) {
return emptyWidget;
}

final oauthStrategies = authState.env.config.identificationStrategies //
.where((i) => i.isOauth)
.toList();
final socialConnections = authState.env.user.socialSettings.values //
.where((s) => oauthStrategies.contains(s.strategy))
.toList();
final socialConnections = authState.env.socialConnections;
if (socialConnections.isEmpty) {
return emptyWidget;
}

if (socialConnections.isEmpty) {
return emptyWidget;
}

return Row(
children: [
for (final (index, connection) in socialConnections.indexed) ...[
if (index > 0) //
horizontalMargin8,
Expanded(
child: SocialConnectionButton(
key: ValueKey<clerk.SocialConnection>(connection),
connection: connection,
onPressed: () => widget.onStrategyChosen(connection.strategy),
),
),
],
],
return Row(
children: [
for (final (index, connection) in socialConnections.indexed) ...[
if (index > 0) //
horizontalMargin8,
Expanded(
child: SocialConnectionButton(
key: ValueKey<clerk.SocialConnection>(connection),
connection: connection,
onPressed: () => widget.onStrategyChosen(connection.strategy),
),
),
]
],
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:clerk_flutter/src/utils/clerk_sdk_localization_ext.dart';
import 'package:clerk_flutter/src/utils/clerk_telemetry.dart';
import 'package:clerk_flutter/src/utils/localization_extensions.dart';
import 'package:clerk_flutter/src/widgets/ui/clerk_code_input.dart';
import 'package:clerk_flutter/src/widgets/ui/clerk_continue_button.dart';
import 'package:clerk_flutter/src/widgets/ui/clerk_material_button.dart';
import 'package:clerk_flutter/src/widgets/ui/clerk_phone_number_form_field.dart';
import 'package:clerk_flutter/src/widgets/ui/clerk_text_form_field.dart';
Expand Down Expand Up @@ -311,19 +312,7 @@ class _ClerkSignUpPanelState extends State<ClerkSignUpPanel>
Closeable(
closed: (_state.isWaiting && isAwaitingCode == false) ||
(_needsLegalAcceptance && _hasLegalAcceptance == false),
child: ClerkMaterialButton(
onPressed: () => _continue(attributes),
label: Row(
children: [
horizontalMargin16,
Expanded(child: Center(child: Text(l10ns.cont))),
const SizedBox(
width: 16,
child: Icon(Icons.arrow_right_sharp),
),
],
),
),
child: ClerkContinueButton(onPressed: () => _continue(attributes)),
),
if (_needsLegalAcceptance) //
Closeable(
Expand Down
Loading