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

feat!: Upgrade anonymous users to regular users automatically if opted in #100

Merged
merged 1 commit 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
27 changes: 21 additions & 6 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,27 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
);
widget.onSignInComplete.call(response);
} else {
final response = await supabase.auth.signUp(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
emailRedirectTo: widget.redirectTo,
data: _resolveData(),
);
final user = supabase.auth.currentUser;
late final AuthResponse response;
if (user?.isAnonymous == true) {
await supabase.auth.updateUser(
UserAttributes(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
data: _resolveData(),
),
emailRedirectTo: widget.redirectTo,
);
final newSession = supabase.auth.currentSession;
response = AuthResponse(session: newSession);
} else {
response = await supabase.auth.signUp(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
emailRedirectTo: widget.redirectTo,
data: _resolveData(),
);
}
widget.onSignUpComplete.call(response);
}
} on AuthException catch (error) {
Expand Down
17 changes: 15 additions & 2 deletions lib/src/components/supa_phone_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,21 @@ class _SupaPhoneAuthState extends State<SupaPhoneAuth> {
);
widget.onSuccess(response);
} else {
final response = await supabase.auth
.signUp(phone: _phone.text, password: _password.text);
late final AuthResponse response;
final user = supabase.auth.currentUser;
if (user?.isAnonymous == true) {
await supabase.auth.updateUser(
UserAttributes(
phone: _phone.text,
password: _password.text,
),
);
} else {
response = await supabase.auth.signUp(
phone: _phone.text,
password: _password.text,
);
}
if (!mounted) return;
widget.onSuccess(response);
}
Expand Down
11 changes: 11 additions & 0 deletions lib/src/components/supa_socials_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ class _SupaSocialsAuthState extends State<SupaSocialsAuth> {
}
}

final user = supabase.auth.currentUser;
if (user?.isAnonymous == true) {
await supabase.auth.linkIdentity(
socialProvider,
redirectTo: widget.redirectUrl,
scopes: widget.scopes?[socialProvider],
queryParams: widget.queryParams?[socialProvider],
);
return;
}

await supabase.auth.signInWithOAuth(
socialProvider,
redirectTo: widget.redirectUrl,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
supabase_flutter: ^2.3.4
supabase_flutter: ^2.5.6
email_validator: ^2.0.1
font_awesome_flutter: ^10.6.0
google_sign_in: ^6.2.1
Expand Down
Loading