Skip to content

feat: Add prefilled email, password to SupaEmailAuth #143

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import 'package:flutter/material.dart';
import 'package:supabase_auth_ui/supabase_auth_ui.dart';

import './home.dart';
import './sign_in.dart';
import './magic_link.dart';
import './phone_sign_in.dart';
import './sign_in.dart';
import './sign_in_prefilled.dart';
import './update_password.dart';
import 'phone_sign_in.dart';
import './verify_phone.dart';

void main() async {
Expand Down Expand Up @@ -34,14 +35,15 @@ class MyApp extends StatelessWidget {
border: OutlineInputBorder(),
),
),
initialRoute: '/',
initialRoute: '/prefilled',
routes: {
'/': (context) => const SignUp(),
'/magic_link': (context) => const MagicLink(),
'/update_password': (context) => const UpdatePassword(),
'/phone_sign_in': (context) => const PhoneSignIn(),
'/phone_sign_up': (context) => const PhoneSignUp(),
'/verify_phone': (context) => const VerifyPhone(),
'/prefilled': (context) => const SignInPrefilled(),
'/home': (context) => const Home(),
},
onUnknownRoute: (RouteSettings settings) {
Expand Down
68 changes: 68 additions & 0 deletions example/lib/sign_in_prefilled.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:supabase_auth_ui/supabase_auth_ui.dart';

import 'constants.dart';

class SignInPrefilled extends StatelessWidget {
const SignInPrefilled({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
void navigateHome(AuthResponse response) {
Navigator.of(context).pushReplacementNamed('/home');
}

return Scaffold(
appBar: appBar('Sign In (Prefilled)'),
body: ListView(
padding: const EdgeInsets.all(24.0),
children: [
SupaEmailAuth(
prefilledEmail: "[email protected]",
prefilledPassword: "password",
redirectTo: kIsWeb ? null : 'io.supabase.flutter://',
onSignInComplete: navigateHome,
onSignUpComplete: navigateHome,
metadataFields: [
MetaDataField(
prefixIcon: const Icon(Icons.person),
label: 'Username',
key: 'username',
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter something';
}
return null;
},
),
BooleanMetaDataField(
label: 'Keep me up to date with the latest news and updates.',
key: 'marketing_consent',
checkboxPosition: ListTileControlAffinity.leading,
),
BooleanMetaDataField(
key: 'terms_agreement',
isRequired: true,
checkboxPosition: ListTileControlAffinity.leading,
richLabelSpans: [
const TextSpan(text: 'I have read and agree to the '),
TextSpan(
text: 'Terms and Conditions',
style: const TextStyle(
color: Colors.blue,
),
recognizer: TapGestureRecognizer()
..onTap = () {
// Handle tap on Terms and Conditions
},
),
],
),
],
),
],
),
);
}
}
10 changes: 10 additions & 0 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ class SupaEmailAuth extends StatefulWidget {
/// Whether the confirm password field should be displayed
final bool showConfirmPasswordField;

/// Pre-filled email for the form
final String? prefilledEmail;

/// Pre-filled password for the form
final String? prefilledPassword;

/// {@macro supa_email_auth}
const SupaEmailAuth({
super.key,
Expand All @@ -240,6 +246,8 @@ class SupaEmailAuth extends StatefulWidget {
this.prefixIconEmail = const Icon(Icons.email),
this.prefixIconPassword = const Icon(Icons.lock),
this.showConfirmPasswordField = false,
this.prefilledEmail,
this.prefilledPassword,
});

@override
Expand All @@ -265,6 +273,8 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
@override
void initState() {
super.initState();
_emailController.text = widget.prefilledEmail ?? '';
_passwordController.text = widget.prefilledPassword ?? '';
_isSigningIn = widget.isInitiallySigningIn;
_metadataControllers = Map.fromEntries((widget.metadataFields ?? []).map(
(metadataField) => MapEntry(
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: supabase_auth_ui
description: UI library to implement auth forms using Supabase and Flutter
version: 0.5.5
version: 0.5.6
homepage: https://supabase.com
repository: 'https://github.com/supabase-community/flutter-auth-ui'

Expand All @@ -12,10 +12,10 @@ dependencies:
flutter:
sdk: flutter
supabase_flutter: ^2.5.6
email_validator: ^2.0.1
email_validator: ^3.0.0
font_awesome_flutter: ^10.6.0
google_sign_in: ^6.2.1
sign_in_with_apple: ^6.1.0
sign_in_with_apple: ^7.0.1
crypto: ^3.0.3

dev_dependencies:
Expand Down