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(authentication): add reauthenticateWithCredential method #545

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions packages/authentication/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ export interface FirebaseAuthenticationPlugin {
* @since 1.1.0
*/
linkWithYahoo(options?: LinkWithOAuthOptions): Promise<LinkResult>;
/**
* Reauthenticates the current user with the provided credential.
*
* @since 1.1.0
*/
reauthenticateWithCredential(
options: ReauthenticateWithCredentialOptions,
): Promise<void>;
/**
* Reloads user account data, if signed in.
*
Expand Down Expand Up @@ -592,6 +600,15 @@ export interface GetTenantIdResult {
tenantId: string | null;
}

export interface ReauthenticateWithCredentialOptions {
/**
* The credential to reauthenticate.
*
* @since 5.3.0
*/
credential: AuthCredential;
}

/**
* @since 0.2.2
*/
Expand Down
17 changes: 17 additions & 0 deletions packages/authentication/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
connectAuthEmulator,
createUserWithEmailAndPassword,
deleteUser,
reauthenticateWithCredential as firebaseReauthenticateWithCredential,
getAdditionalUserInfo,
getAuth,
getRedirectResult,
Expand Down Expand Up @@ -75,6 +76,7 @@ import type {
LinkWithPhoneNumberOptions,
PhoneCodeSentEvent,
PhoneVerificationFailedEvent,
ReauthenticateWithCredentialOptions,
SendPasswordResetEmailOptions,
SendSignInLinkToEmailOptions,
SetLanguageCodeOptions,
Expand Down Expand Up @@ -391,6 +393,21 @@ export class FirebaseAuthenticationWeb
return this.createSignInResult(userCredential, authCredential);
}

public async reauthenticateWithCredential(
options: ReauthenticateWithCredentialOptions,
): Promise<void> {
const auth = getAuth();
const currentUser = auth.currentUser;
if (!currentUser) {
throw new Error(FirebaseAuthenticationWeb.ERROR_NO_USER_SIGNED_IN);
}
const credential = EmailAuthProvider.credential(
options.email,
options.password,
);
await firebaseReauthenticateWithCredential(currentUser, credential);
}

public async reload(): Promise<void> {
const auth = getAuth();
const currentUser = auth.currentUser;
Expand Down
Loading