Skip to content

feat!: Allow the OAuth provider labels to be overridden on SupaSocialsAuth #101

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

Merged
merged 6 commits into from
Jun 20, 2024
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
7 changes: 5 additions & 2 deletions lib/src/components/supa_socials_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ extension on OAuthProvider {
_ => Colors.black,
};

String get capitalizedName => name[0].toUpperCase() + name.substring(1);
String get labelText =>
'Continue with ${name[0].toUpperCase()}${name.substring(1)}';
}

enum SocialButtonVariant {
Expand Down Expand Up @@ -384,7 +385,9 @@ class _SupaSocialsAuthState extends State<SupaSocialsAuth> {
style: authButtonStyle,
onPressed: onAuthButtonPressed,
label: Text(
'${localization.continueWith} ${socialProvider.capitalizedName}'),
localization.oAuthButtonLabels[socialProvider] ??
socialProvider.labelText,
),
),
);
},
Expand Down
26 changes: 22 additions & 4 deletions lib/src/localizations/supa_socials_auth_localization.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import 'package:supabase_auth_ui/supabase_auth_ui.dart';

class SupaSocialsAuthLocalization {
final String updatePassword;
final String successSignInMessage;
final String unexpectedError;
final String continueWith;

/// Overrides the name of the OAuth provider shown on the sign-in button.
///
/// Defaults to `Continue with [ProviderName]`
///
/// ```dart
/// SupaSocialsAuth(
/// socialProviders: const [OAuthProvider.azure],
/// localization: const SupaSocialsAuthLocalization(
/// oAuthButtonLabels: {
/// OAuthProvider.azure: 'Microsoft (Azure)'
/// },
/// ),
/// onSuccess: (session) {
/// // sHandle success
/// },
/// ),
/// ```
final Map<OAuthProvider, String> oAuthButtonLabels;

const SupaSocialsAuthLocalization({
this.updatePassword = 'Update Password',
this.successSignInMessage = 'Successfully signed in!',
this.unexpectedError = 'An unexpected error occurred',
this.continueWith = 'Continue with',
this.oAuthButtonLabels = const {},
});
}