Skip to content
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

Headless signup user metadata option #69

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Changes from 1 commit
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
23 changes: 18 additions & 5 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class SupaEmailAuth extends StatefulWidget {

final List<MetaDataField>? metadataFields;

final Map<String, dynamic>? extraMetadata;
tomasAlabes marked this conversation as resolved.
Show resolved Hide resolved

/// {@macro supa_email_auth}
const SupaEmailAuth({
Key? key,
Expand All @@ -83,6 +85,7 @@ class SupaEmailAuth extends StatefulWidget {
this.onPasswordResetEmailSent,
this.onError,
this.metadataFields,
this.extraMetadata
}) : super(key: key);

@override
Expand Down Expand Up @@ -204,11 +207,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
emailRedirectTo: widget.redirectTo,
data: widget.metadataFields == null
? null
: _metadataControllers.map<String, dynamic>(
(metaDataField, controller) =>
MapEntry(metaDataField.key, controller.text)),
data: _resolveData(),
);
widget.onSignUpComplete.call(response);
}
Expand Down Expand Up @@ -295,4 +294,18 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
),
);
}

Map<String, dynamic> _resolveData() {
var extra = widget.extraMetadata ?? <String, dynamic>{};
extra.addAll(_resolveMetadataFieldsData());
return extra;
}

Map<String, dynamic> _resolveMetadataFieldsData() {
return widget.metadataFields != null
? _metadataControllers.map<String, dynamic>(
(metaDataField, controller) =>
MapEntry(metaDataField.key, controller.text))
: <String, dynamic>{};
}
}