Skip to content
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
8 changes: 8 additions & 0 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ Since code should be documenting itself you can also take a look at the followin
- [tests/.../AuthFixture.cs](https://github.com/TobiasBuchholz/Plugin.Firebase/blob/master/tests/Plugin.Firebase.IntegrationTests/Auth/AuthFixture.cs)
- [sample/.../AuthService.cs](https://github.com/TobiasBuchholz/Plugin.Firebase/blob/master/sample/Playground/Common/Services/Auth/AuthService.cs)

## Language

Use `SetLanguageCode("fr")` (or any BCP-47 code) before invoking an Auth flow that triggers user-facing content such as password-reset emails, email-verification emails, or phone-auth SMS.
Pass `null` or whitespace to reset to the app language (`UseAppLanguage`).

## Error handling

Most Auth operations can throw `FirebaseAuthException`.
Expand All @@ -79,6 +84,9 @@ The exception contains:
- `Email`: populated for account-collision cases when available

## Release notes
- Version 4.1.0
- Add `ReloadCurrentUserAsync()` to refresh the currently signed in user from the backend.
- Add `SetLanguageCode(string?)` to control the language used for Auth-generated user-facing flows (reset/verification emails, SMS).
- Version 4.0.1
- Improve `FirebaseAuthException` mapping and expose raw error details (`ErrorCode`, `Email`, and native error metadata) to support robust UI handling.
- Version 4.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/Analytics/Analytics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.Analytics</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/Auth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.Auth</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
22 changes: 22 additions & 0 deletions src/Auth/Platforms/Android/FirebaseAuthImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ public async Task SendPasswordResetEmailAsync(string email)
await WrapAsync(_firebaseAuth.SendPasswordResetEmailAsync(email));
}

public async Task ReloadCurrentUserAsync()
{
var currentUser = _firebaseAuth.CurrentUser;
if(currentUser is null) {
throw new FirebaseException(
"CurrentUser is null. You need to be logged in to use this feature."
);
}

await WrapAsync(currentUser.ReloadAsync());
}

public void SetLanguageCode(string? languageCode)
{
if(string.IsNullOrWhiteSpace(languageCode)) {
_firebaseAuth.UseAppLanguage();
return;
}

_firebaseAuth.LanguageCode = languageCode;
}

public void UseEmulator(string host, int port)
{
_firebaseAuth.UseEmulator(host, port);
Expand Down
30 changes: 27 additions & 3 deletions src/Auth/Platforms/iOS/FirebaseAuthImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ public Task SignOutAsync()
{
_firebaseAuth.SignOut(out var error);

return error is null
? Task.CompletedTask
: throw GetFirebaseAuthException(new NSErrorException(error));
if(error is null) {
return Task.CompletedTask;
}

throw GetFirebaseAuthException(new NSErrorException(error));
}

/// <inheritdoc/>
Expand Down Expand Up @@ -180,6 +182,28 @@ public async Task SendPasswordResetEmailAsync(string email)
await WrapAsync(_firebaseAuth.SendPasswordResetAsync(email));
}

public async Task ReloadCurrentUserAsync()
{
var currentUser = _firebaseAuth.CurrentUser;
if(currentUser is null) {
throw new FirebaseException(
"CurrentUser is null. You need to be logged in to use this feature."
);
}

await WrapAsync(currentUser.ReloadAsync());
}

public void SetLanguageCode(string? languageCode)
{
if(string.IsNullOrWhiteSpace(languageCode)) {
_firebaseAuth.UseAppLanguage();
return;
}

_firebaseAuth.LanguageCode = languageCode;
}

/// <inheritdoc/>
public void UseEmulator(string host, int port)
{
Expand Down
13 changes: 13 additions & 0 deletions src/Auth/Shared/IFirebaseAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ Task<IFirebaseUser> SignInWithEmailAndPasswordAsync(
/// <param name="email">The registered user email.</param>
Task SendPasswordResetEmailAsync(string email);

/// <summary>
/// Reloads the currently signed in user from the backend.
/// </summary>
/// <exception cref="Plugin.Firebase.Core.Exceptions.FirebaseException">Thrown when no user is signed in.</exception>
Task ReloadCurrentUserAsync();

/// <summary>
/// Sets the language used by Firebase Auth for user-facing flows such as Auth-generated emails/SMS (password reset, email verification, phone auth).
/// Call this before invoking an API that triggers the flow, then reset by passing null/whitespace to use the app language.
/// </summary>
/// <param name="languageCode">A BCP-47 language code (e.g. "fr", "en-GB"), or null to use app language.</param>
void SetLanguageCode(string? languageCode);

/// <summary>
/// Modify this FirebaseAuth instance to communicate with the Firebase Authentication emulator.
/// Note: this must be called before this instance has been used to do any operations.
Expand Down
2 changes: 1 addition & 1 deletion src/Bundled/Bundled.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/CloudMessaging/CloudMessaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.CloudMessaging</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.Core</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Crashlytics/Crashlytics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.Crashlytics</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Firestore/Firestore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.Firestore</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Functions/Functions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.Functions</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/RemoteConfig/RemoteConfig.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.RemoteConfig</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--Assembly and Namespace info -->
<PackageId>Plugin.Firebase.Storage</PackageId>
<PackageVersion>4.0.2</PackageVersion>
<PackageVersion>4.1.0</PackageVersion>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TobiasBuchholz/Plugin.Firebase</PackageProjectUrl>
Expand Down
28 changes: 28 additions & 0 deletions tests/Plugin.Firebase.IntegrationTests/Auth/AuthFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,34 @@ public async Task sends_verification_email()
await sut.CurrentUser.SendEmailVerificationAsync();
}

[Fact]
public async Task reloads_current_user()
{
var sut = CrossFirebaseAuth.Current;
await sut.SignInWithEmailAndPasswordAsync("reload-current-user@test.com", "123456");
Assert.NotNull(sut.CurrentUser);

var uid = sut.CurrentUser.Uid;
await sut.ReloadCurrentUserAsync();

Assert.NotNull(sut.CurrentUser);
Assert.Equal(uid, sut.CurrentUser.Uid);
}

[Fact]
public async Task sets_language_code()
{
var sut = CrossFirebaseAuth.Current;
await sut.SignInWithEmailAndPasswordAsync("set-language-code@test.com", "123456");

var ex = Record.Exception(() => {
sut.SetLanguageCode("fr");
sut.SetLanguageCode(null);
sut.SetLanguageCode(" ");
});
Assert.Null(ex);
}

[Fact]
public async Task deletes_user()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ public sealed class FirebaseAuthExceptionTests
new object[] { "ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL", FIRAuthError.AccountExistsWithDifferentCredential },
new object[] { "ERROR_CREDENTIAL_ALREADY_IN_USE", FIRAuthError.CredentialAlreadyInUse },
new object[] { "ERROR_REQUIRES_RECENT_LOGIN", FIRAuthError.RequiresRecentLogin },
new object[] { "RequiresRecentLogin", FIRAuthError.RequiresRecentLogin },
new object[] { "FIRAuthErrorCodeRequiresRecentLogin", FIRAuthError.RequiresRecentLogin },
new object[] { "AuthErrorCodeRequiresRecentLogin", FIRAuthError.RequiresRecentLogin },
new object[] { "ERROR_OPERATION_NOT_ALLOWED", FIRAuthError.OperationNotAllowed },
new object[] { "ERROR_INVALID_CUSTOM_TOKEN", FIRAuthError.InvalidCustomToken },
new object[] { "ERROR_CUSTOM_TOKEN_MISMATCH", FIRAuthError.CustomTokenMismatch },
new object[] { "ERROR_INVALID_USER_TOKEN", FIRAuthError.InvalidUserToken },
new object[] { "ERROR_USER_TOKEN_EXPIRED", FIRAuthError.UserTokenExpired },
new object[] { "FIRAuthErrorCodeUserTokenExpired", FIRAuthError.UserTokenExpired },
new object[] { "ERROR_KEYCHAIN_ERROR", FIRAuthError.KeychainError },
new object[] { "ERROR_INTERNAL_ERROR", FIRAuthError.InternalError },
new object[] { "ERROR_TOO_MANY_REQUESTS", FIRAuthError.TooManyRequests },
Expand Down Expand Up @@ -60,4 +65,4 @@ public void FromErrorCode_preserves_metadata()
Assert.Equal("domain", exception.NativeErrorDomain);
Assert.Equal(123, exception.NativeErrorCode);
}
}
}