Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d9eb81e
refactor(core): Align current API with new spec
Ehesp Sep 11, 2025
342411a
refactor: Reorganize test files
Ehesp Sep 11, 2025
a2a6013
feat: Add CardContent component
Ehesp Sep 11, 2025
ff9b668
feat(react): Support allowedCountries prop
Ehesp Sep 11, 2025
0ec2f6d
chore: Improve card child props
Ehesp Sep 11, 2025
5d1bd7d
refactor: Update element props api usage
Ehesp Sep 11, 2025
9e8314c
feat(react): Add provider prop to GoogleSignInButton
Ehesp Sep 11, 2025
69db89c
refactor(react): Align EmailLinkAuth{Form,Screen} components with API…
Ehesp Sep 11, 2025
a366371
refactor: Align OAuthScreen with API spec
Ehesp Sep 11, 2025
e765077
refactor(react): Align ForgotPasswordAuth{Screen,Form} with API spec
Ehesp Sep 11, 2025
4edd8f1
refactor: Align PhoneAuth{Screen,Form} with API spec
Ehesp Sep 11, 2025
f04c478
refactor(react): Align SignInAuth{Screen,Form} with API spec
Ehesp Sep 11, 2025
28573f2
refactor(react): Align SignUpAuth{Screen,Form} with API spec
Ehesp Sep 11, 2025
2486915
chore(react): Align polciies/toc naming
Ehesp Sep 11, 2025
74c37e4
refactor: Sync country data and phone auth changes
Ehesp Sep 11, 2025
7a38280
refactor(react): Url -> PolicyURL
Ehesp Sep 11, 2025
ad74074
fix(react): Ensure all components + props are exported
Ehesp Sep 11, 2025
cd0f20a
refactor(react): ConfigProvider -> FirebaseUIProvider
Ehesp Sep 11, 2025
5adb13d
fix(react): Update integration test imports
Ehesp Sep 11, 2025
6a24440
Merge branch '@invertase/v7-development' of https://github.com/fireba…
Ehesp Sep 11, 2025
7026f66
Merge branch '@invertase/align-core' of https://github.com/firebase/f…
Ehesp Sep 11, 2025
0fe96cf
refactor(react): Use CVA buttonVariant from styles
Ehesp Sep 11, 2025
e40028a
chore(react): Fix type imports in tests
Ehesp Sep 11, 2025
e44cda0
chore: Remove unused import
Ehesp Sep 12, 2025
d9d6d97
Merge branch '@invertase/align-core' of https://github.com/firebase/f…
Ehesp Sep 12, 2025
2581ac3
refactor(core): createEmailFormSchema -> createSignInAuthFormSchema
Ehesp Sep 12, 2025
a505368
refactor(core): createForgotPasswordFormSchema -> createForgotPasswor…
Ehesp Sep 12, 2025
1b41b1f
feat(core): Support createSignUpAuthFormSchema
Ehesp Sep 12, 2025
70ec109
refactor(core): createEmailLinkFormSchema -> createEmailLinkAuthFormS…
Ehesp Sep 12, 2025
fbf457b
refactor(core): createPhoneFormSchema -> createPhoneAuthFormSchema
Ehesp Sep 12, 2025
3c1e51f
Merge branch '@invertase/align-core' of https://github.com/firebase/f…
Ehesp Sep 12, 2025
ac08d1d
refactor(react): Align react with core changes
Ehesp Sep 12, 2025
489dd4c
refactor(core): signInWithOAuth -> signInWithProvider
Ehesp Sep 12, 2025
014c54f
test(core): Refactor auth.ts tests
Ehesp Sep 15, 2025
f773ae1
test(core): Add schemas tests
Ehesp Sep 15, 2025
e78d0b7
test(core): Add translations tests
Ehesp Sep 15, 2025
78151cc
tests(core): Add country-data tests
Ehesp Sep 15, 2025
d646786
chore: Remove file
Ehesp Sep 15, 2025
2f3e9b5
feat(core): Add behavior tests
Ehesp Sep 15, 2025
b03e310
test(core): Add config tests
Ehesp Sep 15, 2025
17a8d74
test(core): Remove old file
Ehesp Sep 15, 2025
abb48ce
test(core): Update integration test import
Ehesp Sep 15, 2025
6fd8ed5
test(core): Add error tests
Ehesp Sep 16, 2025
c2fa4d4
chore(core): Cleanup tests / scripts
Ehesp Sep 16, 2025
9a23ee8
Merge pull request #1183 from firebase/@invertase/align-core-tests
Ehesp Sep 17, 2025
19a3ef4
chore(core): Upgrade zod version
Ehesp Sep 17, 2025
b5c45c4
Merge pull request #1182 from firebase/@invertase/align-react
Ehesp Sep 17, 2025
d42c8d9
Merge branch '@invertase/v7-development' of https://github.com/fireba…
Ehesp Sep 18, 2025
8c7f25b
Merge branch '@invertase/v7-development' of https://github.com/fireba…
Ehesp Sep 26, 2025
f63fc32
refactor(core,styles,translations): Align tsconfigs
Ehesp Sep 26, 2025
d2cbb65
feat(core): Support recaptchaVerification behavior
Ehesp Sep 30, 2025
b60f7fc
Merge pull request #1202 from firebase/@invertase/core-recaptcha-veri…
Ehesp Sep 30, 2025
6e70048
Merge branch '@invertase/v7-development' of https://github.com/fireba…
Ehesp Oct 1, 2025
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
9 changes: 5 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
"clean": "rimraf dist",
"test:unit": "vitest run tests/unit",
"test:unit:watch": "vitest tests/unit",
"test:integration": "vitest run tests/integration",
"test:integration:watch": "vitest tests/integration",
"test:unit": "vitest run src",
"test:unit:watch": "vitest tests",
"test:integration": "vitest run tests",
"test:integration:watch": "vitest integration",
"test": "vitest run",
"publish:tags": "sh -c 'TAG=\"${npm_package_name}@${npm_package_version}\"; git tag --list \"$TAG\" | grep . || git tag \"$TAG\"; git push origin \"$TAG\"'",
"release": "pnpm run build && pnpm pack --pack-destination --pack-destination ../../releases/"
Expand Down Expand Up @@ -60,6 +60,7 @@
"tsup": "catalog:",
"typescript": "catalog:",
"vite": "catalog:",
"vitest-tsconfig-paths": "catalog:",
"vitest": "catalog:"
}
}
802 changes: 802 additions & 0 deletions packages/core/src/auth.test.ts

Large diffs are not rendered by default.

70 changes: 30 additions & 40 deletions packages/core/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import {
signInAnonymously as _signInAnonymously,
signInWithPhoneNumber as _signInWithPhoneNumber,
ActionCodeSettings,
ApplicationVerifier,
AuthProvider,
ConfirmationResult,
EmailAuthProvider,
getAuth,
linkWithCredential,
PhoneAuthProvider,
RecaptchaVerifier,
signInWithCredential,
signInWithRedirect,
UserCredential,
Expand All @@ -43,7 +42,7 @@ async function handlePendingCredential(ui: FirebaseUIConfiguration, user: UserCr

try {
const pendingCred = JSON.parse(pendingCredString);
ui.setState("linking");
ui.setState("pending");
const result = await linkWithCredential(user.user, pendingCred);
ui.setState("idle");
window.sessionStorage.removeItem("pendingCred");
Expand All @@ -60,19 +59,18 @@ export async function signInWithEmailAndPassword(
password: string
): Promise<UserCredential> {
try {
const auth = getAuth(ui.app);
const credential = EmailAuthProvider.credential(email, password);

if (hasBehavior(ui, "autoUpgradeAnonymousCredential")) {
const result = await getBehavior(ui, "autoUpgradeAnonymousCredential")(ui, credential);

if (result) {
return handlePendingCredential(ui, result);
}
}

ui.setState("signing-in");
const result = await signInWithCredential(auth, credential);
ui.setState("pending");
const result = await signInWithCredential(ui.auth, credential);
return handlePendingCredential(ui, result);
} catch (error) {
handleFirebaseError(ui, error);
Expand All @@ -87,7 +85,6 @@ export async function createUserWithEmailAndPassword(
password: string
): Promise<UserCredential> {
try {
const auth = getAuth(ui.app);
const credential = EmailAuthProvider.credential(email, password);

if (hasBehavior(ui, "autoUpgradeAnonymousCredential")) {
Expand All @@ -98,8 +95,8 @@ export async function createUserWithEmailAndPassword(
}
}

ui.setState("creating-user");
const result = await _createUserWithEmailAndPassword(auth, email, password);
ui.setState("pending");
const result = await _createUserWithEmailAndPassword(ui.auth, email, password);
return handlePendingCredential(ui, result);
} catch (error) {
handleFirebaseError(ui, error);
Expand All @@ -111,12 +108,11 @@ export async function createUserWithEmailAndPassword(
export async function signInWithPhoneNumber(
ui: FirebaseUIConfiguration,
phoneNumber: string,
recaptchaVerifier: RecaptchaVerifier
appVerifier: ApplicationVerifier
): Promise<ConfirmationResult> {
try {
const auth = getAuth(ui.app);
ui.setState("signing-in");
return await _signInWithPhoneNumber(auth, phoneNumber, recaptchaVerifier);
ui.setState("pending");
return await _signInWithPhoneNumber(ui.auth, phoneNumber, appVerifier);
} catch (error) {
handleFirebaseError(ui, error);
} finally {
Expand All @@ -130,8 +126,7 @@ export async function confirmPhoneNumber(
verificationCode: string
): Promise<UserCredential> {
try {
const auth = getAuth(ui.app);
const currentUser = auth.currentUser;
const currentUser = ui.auth.currentUser;
const credential = PhoneAuthProvider.credential(confirmationResult.verificationId, verificationCode);

if (currentUser?.isAnonymous && hasBehavior(ui, "autoUpgradeAnonymousCredential")) {
Expand All @@ -142,8 +137,8 @@ export async function confirmPhoneNumber(
}
}

ui.setState("signing-in");
const result = await signInWithCredential(auth, credential);
ui.setState("pending");
const result = await signInWithCredential(ui.auth, credential);
return handlePendingCredential(ui, result);
} catch (error) {
handleFirebaseError(ui, error);
Expand All @@ -154,9 +149,8 @@ export async function confirmPhoneNumber(

export async function sendPasswordResetEmail(ui: FirebaseUIConfiguration, email: string): Promise<void> {
try {
const auth = getAuth(ui.app);
ui.setState("sending-password-reset-email");
await _sendPasswordResetEmail(auth, email);
ui.setState("pending");
await _sendPasswordResetEmail(ui.auth, email);
} catch (error) {
handleFirebaseError(ui, error);
} finally {
Expand All @@ -166,16 +160,15 @@ export async function sendPasswordResetEmail(ui: FirebaseUIConfiguration, email:

export async function sendSignInLinkToEmail(ui: FirebaseUIConfiguration, email: string): Promise<void> {
try {
const auth = getAuth(ui.app);

const actionCodeSettings = {
url: window.location.href,
// TODO(ehesp): Check this...
handleCodeInApp: true,
} satisfies ActionCodeSettings;

ui.setState("sending-sign-in-link-to-email");
await _sendSignInLinkToEmail(auth, email, actionCodeSettings);
ui.setState("pending");
await _sendSignInLinkToEmail(ui.auth, email, actionCodeSettings);
// TODO: Should this be a behavior ("storageStrategy")?
window.localStorage.setItem("emailForSignIn", email);
} catch (error) {
handleFirebaseError(ui, error);
Expand All @@ -190,7 +183,6 @@ export async function signInWithEmailLink(
link: string
): Promise<UserCredential> {
try {
const auth = ui.getAuth();
const credential = EmailAuthProvider.credentialWithLink(email, link);

if (hasBehavior(ui, "autoUpgradeAnonymousCredential")) {
Expand All @@ -200,8 +192,8 @@ export async function signInWithEmailLink(
}
}

ui.setState("signing-in");
const result = await signInWithCredential(auth, credential);
ui.setState("pending");
const result = await signInWithCredential(ui.auth, credential);
return handlePendingCredential(ui, result);
} catch (error) {
handleFirebaseError(ui, error);
Expand All @@ -212,9 +204,8 @@ export async function signInWithEmailLink(

export async function signInAnonymously(ui: FirebaseUIConfiguration): Promise<UserCredential> {
try {
const auth = getAuth(ui.app);
ui.setState("signing-in");
const result = await _signInAnonymously(auth);
ui.setState("pending");
const result = await _signInAnonymously(ui.auth);
return handlePendingCredential(ui, result);
} catch (error) {
handleFirebaseError(ui, error);
Expand All @@ -223,18 +214,18 @@ export async function signInAnonymously(ui: FirebaseUIConfiguration): Promise<Us
}
}

export async function signInWithOAuth(ui: FirebaseUIConfiguration, provider: AuthProvider): Promise<void> {
export async function signInWithProvider(ui: FirebaseUIConfiguration, provider: AuthProvider): Promise<void> {
try {
const auth = getAuth(ui.app);

if (hasBehavior(ui, "autoUpgradeAnonymousProvider")) {
await getBehavior(ui, "autoUpgradeAnonymousProvider")(ui, provider);
// If we get to here, the user is not anonymous, otherwise they
// have been redirected to the provider's sign in page.
}

ui.setState("signing-in");
await signInWithRedirect(auth, provider);
ui.setState("pending");

// TODO(ehesp): Handle popup or redirect based on behavior
await signInWithRedirect(ui.auth, provider);
// We don't modify state here since the user is redirected.
// If we support popups, we'd need to modify state here.
} catch (error) {
Expand All @@ -249,17 +240,16 @@ export async function completeEmailLinkSignIn(
currentUrl: string
): Promise<UserCredential | null> {
try {
const auth = ui.getAuth();
if (!_isSignInWithEmailLink(auth, currentUrl)) {
if (!_isSignInWithEmailLink(ui.auth, currentUrl)) {
return null;
}

const email = window.localStorage.getItem("emailForSignIn");
if (!email) return null;

ui.setState("signing-in");
ui.setState("pending");
const result = await signInWithEmailLink(ui, email, currentUrl);
ui.setState("idle");
ui.setState("idle"); // TODO(ehesp): Do we need this here?
return handlePendingCredential(ui, result);
} catch (error) {
handleFirebaseError(ui, error);
Expand Down
Loading
Loading