Skip to content

Commit b5115f6

Browse files
shinyfordslightfoot
authored andcommitted
feat: force user to create org when required on log in [#271]
1 parent 2f22460 commit b5115f6

18 files changed

+429
-230
lines changed

packages/clerk_auth/lib/src/models/environment/environment.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ class Environment with InformativeToStringMixin {
6262
].contains(i),
6363
);
6464

65+
/// [List] of available social connections i.e. oAuth sign in possibilites
66+
List<SocialConnection> get socialConnections => user.socialSettings.values
67+
.where((s) => oauthStrategies.contains(s.strategy))
68+
.toList(growable: false);
69+
70+
/// Do we have social connections?
71+
bool get hasSocialConnections => socialConnections.isNotEmpty;
72+
6573
/// Do we have identification strategies?
6674
bool get hasIdentificationStrategies => identificationStrategies.isNotEmpty;
6775

packages/clerk_auth/lib/src/models/environment/organization_settings.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class OrganizationSettings with InformativeToStringMixin {
1818
this.actions = OrganizationActions.empty,
1919
this.domains = DomainSettings.empty,
2020
this.isEnabled = false,
21+
this.forceOrganizationSelection = false,
2122
});
2223

2324
/// max allowed memberships
@@ -32,9 +33,15 @@ class OrganizationSettings with InformativeToStringMixin {
3233
/// organization actions
3334
final OrganizationActions actions;
3435

36+
/// force organization selection
37+
final bool forceOrganizationSelection;
38+
3539
/// empty [OrganizationSettings]
3640
static const empty = OrganizationSettings();
3741

42+
/// do we allow personal orgs?
43+
bool get allowsPersonalOrgs => forceOrganizationSelection == false;
44+
3845
/// is enabled?
3946
@JsonKey(name: 'enabled')
4047
final bool isEnabled;

packages/clerk_auth/lib/src/models/environment/organization_settings.g.dart

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/clerk_flutter/example/lib/pages/clerk_sign_in_example.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class ClerkSignInExample extends StatelessWidget {
2222
padding: const EdgeInsets.all(16),
2323
child: ClerkAuthBuilder(
2424
signedInBuilder: (context, authState) {
25-
if (authState.env.organization.isEnabled == false) {
25+
if (authState.env.organization.isEnabled == false ||
26+
authState.user!.hasOrganizations == false) {
2627
return const ClerkUserButton();
2728
}
2829
return const _UserAndOrgTabs();

packages/clerk_flutter/l10n/en.arb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"connectedAccounts": "Connected accounts",
6262
"cont": "Continue",
6363
"createOrganization": "Create organization",
64+
"developmentMode": "Development mode",
6465
"didntReceiveCode": "Didn't receive the code?",
6566
"domainName": "Domain name",
6667
"dontHaveAnAccount": "Don’t have an account?",
@@ -78,6 +79,7 @@
7879
}
7980
},
8081
"enterTheCodeSentToYou": "Enter the code sent to you",
82+
"enterYourOrganizationDetailsToContinue": "Enter your organization details to continue",
8183
"expired": "expired",
8284
"failed": "failed",
8385
"firstName": "first name",
@@ -123,6 +125,7 @@
123125
"logo": "Logo",
124126
"manualInvitation": "Manual invitation",
125127
"missingRequirements": "missing requirements",
128+
"myOrganization": "My Organization",
126129
"name": "Name",
127130
"needsFirstFactor": "needs first factor",
128131
"needsIdentifier": "needs identifier",
@@ -209,6 +212,7 @@
209212
"resetPassword": "Reset password and sign in",
210213
"selectAccount": "Select the account with which you wish to continue",
211214
"sendMeTheCode": "Send me the reset code",
215+
"setUpYourOrganization": "Set up your organization",
212216
"signIn": "Sign in",
213217
"signInByClickingALinkSentToYouByEmail": "Sign in by clicking a link sent to you by email",
214218
"signInByEnteringACodeSentToYouByEmail": "Sign in by entering a code sent to you by email",
@@ -249,6 +253,7 @@
249253
}
250254
}
251255
},
256+
"slug": "Slug",
252257
"slugUrl": "Slug URL",
253258
"switchTo": "Switch to",
254259
"termsAndConditions": "Terms & Conditions",

packages/clerk_flutter/lib/generated/clerk_sdk_localizations.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ abstract class ClerkSdkLocalizations {
276276
/// **'Create organization'**
277277
String get createOrganization;
278278

279+
/// No description provided for @developmentMode.
280+
///
281+
/// In en, this message translates to:
282+
/// **'Development mode'**
283+
String get developmentMode;
284+
279285
/// No description provided for @didntReceiveCode.
280286
///
281287
/// In en, this message translates to:
@@ -336,6 +342,12 @@ abstract class ClerkSdkLocalizations {
336342
/// **'Enter the code sent to you'**
337343
String get enterTheCodeSentToYou;
338344

345+
/// No description provided for @enterYourOrganizationDetailsToContinue.
346+
///
347+
/// In en, this message translates to:
348+
/// **'Enter your organization details to continue'**
349+
String get enterYourOrganizationDetailsToContinue;
350+
339351
/// No description provided for @expired.
340352
///
341353
/// In en, this message translates to:
@@ -438,6 +450,12 @@ abstract class ClerkSdkLocalizations {
438450
/// **'missing requirements'**
439451
String get missingRequirements;
440452

453+
/// No description provided for @myOrganization.
454+
///
455+
/// In en, this message translates to:
456+
/// **'My Organization'**
457+
String get myOrganization;
458+
441459
/// No description provided for @name.
442460
///
443461
/// In en, this message translates to:
@@ -702,6 +720,12 @@ abstract class ClerkSdkLocalizations {
702720
/// **'Send me the reset code'**
703721
String get sendMeTheCode;
704722

723+
/// No description provided for @setUpYourOrganization.
724+
///
725+
/// In en, this message translates to:
726+
/// **'Set up your organization'**
727+
String get setUpYourOrganization;
728+
705729
/// No description provided for @signIn.
706730
///
707731
/// In en, this message translates to:
@@ -774,6 +798,12 @@ abstract class ClerkSdkLocalizations {
774798
/// **'Sign up to {name}'**
775799
String signUpTo(String name);
776800

801+
/// No description provided for @slug.
802+
///
803+
/// In en, this message translates to:
804+
/// **'Slug'**
805+
String get slug;
806+
777807
/// No description provided for @slugUrl.
778808
///
779809
/// In en, this message translates to:

packages/clerk_flutter/lib/generated/clerk_sdk_localizations_en.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
108108
@override
109109
String get createOrganization => 'Create organization';
110110

111+
@override
112+
String get developmentMode => 'Development mode';
113+
111114
@override
112115
String get didntReceiveCode => 'Didn\'t receive the code?';
113116

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

146+
@override
147+
String get enterYourOrganizationDetailsToContinue =>
148+
'Enter your organization details to continue';
149+
143150
@override
144151
String get expired => 'expired';
145152

@@ -199,6 +206,9 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
199206
@override
200207
String get missingRequirements => 'missing requirements';
201208

209+
@override
210+
String get myOrganization => 'My Organization';
211+
202212
@override
203213
String get name => 'Name';
204214

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

362+
@override
363+
String get setUpYourOrganization => 'Set up your organization';
364+
352365
@override
353366
String get signIn => 'Sign in';
354367

@@ -396,6 +409,9 @@ class ClerkSdkLocalizationsEn extends ClerkSdkLocalizations {
396409
return 'Sign up to $name';
397410
}
398411

412+
@override
413+
String get slug => 'Slug';
414+
399415
@override
400416
String get slugUrl => 'Slug URL';
401417

packages/clerk_flutter/lib/src/utils/clerk_sdk_grammar.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ abstract class ClerkSdkGrammar {
6363
/// Current locale can be derived from the [context]
6464
///
6565
String toSentence(String item);
66+
67+
/// Return a slug from a given name
68+
///
69+
/// This needs to return a string that is lowercase, and contains only
70+
/// alphanumeric Latin/Arabic characters and hyphens (which typically replace
71+
/// other characters). Languages that do not use Latin/Arabic characters
72+
/// beware!
73+
///
74+
String toSlug(String name);
6675
}
6776

6877
/// A [ClerkSdkGrammar] default implementation, using English language
@@ -121,4 +130,12 @@ class ClerkSdkGrammarEn implements ClerkSdkGrammar {
121130
@override
122131
String toSentence(String item) =>
123132
item.isNotEmpty ? item[0].toUpperCase() + item.substring(1) : '';
133+
134+
static final _nonAlphaNum = RegExp(r'[^a-z0-9]+');
135+
136+
/// To make a name into a slug in English we lowercase it, remove
137+
/// non-alphanumerics, and replace whitespace with hyphens
138+
@override
139+
String toSlug(String name) =>
140+
name.toLowerCase().replaceAll(_nonAlphaNum, '-');
124141
}

packages/clerk_flutter/lib/src/widgets/authentication/clerk_sign_in_panel.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ class _ClerkSignInPanelState extends State<ClerkSignInPanel>
149149
onStrategyChosen: (strategy) =>
150150
_continue(authState, strategy: strategy),
151151
),
152-
const Padding(padding: verticalPadding24, child: OrDivider()),
152+
if (env.hasSocialConnections) //
153+
const Padding(
154+
padding: verticalPadding24,
155+
child: OrDivider(),
156+
),
153157
ClerkIdentifierInput(
154158
initialValue: _identifier,
155159
strategies: env.identificationStrategies.toList(),

packages/clerk_flutter/lib/src/widgets/authentication/clerk_sign_up_panel.dart

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:clerk_flutter/src/utils/clerk_sdk_localization_ext.dart';
44
import 'package:clerk_flutter/src/utils/clerk_telemetry.dart';
55
import 'package:clerk_flutter/src/utils/localization_extensions.dart';
66
import 'package:clerk_flutter/src/widgets/ui/clerk_code_input.dart';
7+
import 'package:clerk_flutter/src/widgets/ui/clerk_continue_button.dart';
78
import 'package:clerk_flutter/src/widgets/ui/clerk_material_button.dart';
89
import 'package:clerk_flutter/src/widgets/ui/clerk_phone_number_form_field.dart';
910
import 'package:clerk_flutter/src/widgets/ui/clerk_text_form_field.dart';
@@ -303,19 +304,7 @@ class _ClerkSignUpPanelState extends State<ClerkSignUpPanel>
303304
Closeable(
304305
closed: (_state.isWaiting && isAwaitingCode == false) ||
305306
(_needsLegalAcceptance && _hasLegalAcceptance == false),
306-
child: ClerkMaterialButton(
307-
onPressed: () => _continue(attributes),
308-
label: Row(
309-
children: [
310-
horizontalMargin16,
311-
Expanded(child: Center(child: Text(l10ns.cont))),
312-
const SizedBox(
313-
width: 16,
314-
child: Icon(Icons.arrow_right_sharp),
315-
),
316-
],
317-
),
318-
),
307+
child: ClerkContinueButton(onPressed: () => _continue(attributes)),
319308
),
320309
if (_needsLegalAcceptance) //
321310
Closeable(

0 commit comments

Comments
 (0)