Skip to content

Commit 67f690b

Browse files
committed
Merge branch 'main' into feat/auto-link-when-account-exists
2 parents 03511fa + e20f19c commit 67f690b

File tree

14 files changed

+2042
-43
lines changed

14 files changed

+2042
-43
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
integration-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [22.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Setup Java for Firebase Emulator
26+
uses: actions/setup-java@v4
27+
with:
28+
distribution: "temurin"
29+
java-version: "17"
30+
31+
- name: Install pnpm
32+
uses: pnpm/action-setup@v2
33+
with:
34+
version: 8
35+
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Install Firebase Tools
40+
run: npm install -g firebase-tools
41+
42+
- name: Create Firebase config
43+
run: |
44+
cat > firebase.json << EOF
45+
{
46+
"emulators": {
47+
"auth": {
48+
"port": 9099
49+
},
50+
"ui": {
51+
"enabled": false
52+
}
53+
}
54+
}
55+
EOF
56+
57+
- name: Start Firebase Emulator and Run Integration Tests
58+
run: |
59+
firebase emulators:start &
60+
sleep 10
61+
pnpm --filter @firebase-ui/core test:integration

.github/workflows/unit-tests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
unit-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [22.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Install pnpm
26+
uses: pnpm/action-setup@v2
27+
with:
28+
version: 8
29+
30+
- name: Install dependencies
31+
run: pnpm install
32+
33+
- name: Run unit tests
34+
run: pnpm --filter @firebase-ui/core test

packages/firebaseui-core/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Firebase
2+
firebase-debug.log
3+
ui-debug.log
4+
.firebaserc
5+
6+
# Build output
7+
dist/
8+
*.tgz
9+
10+
# Dependencies
11+
node_modules/
12+
13+
# Environment variables
14+
.env*
15+
16+
# IDE
17+
.idea/
18+
.vscode/
19+
*.swp
20+
*.swo
21+
22+
# OS
23+
.DS_Store
24+
Thumbs.db
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"emulators": {
3+
"auth": {
4+
"port": 9099
5+
},
6+
"ui": {
7+
"enabled": true,
8+
"port": 4000
9+
},
10+
"singleProjectMode": true
11+
}
12+
}

packages/firebaseui-core/package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
"build:local": "pnpm run build && pnpm pack",
2222
"dev": "tsup --watch",
2323
"lint": "tsc --noEmit",
24-
"format": "prettier --write \"src/**/*.ts\"",
25-
"clean": "rimraf dist"
24+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
25+
"clean": "rimraf dist",
26+
"test": "vitest run tests/unit",
27+
"test:watch": "vitest tests/unit",
28+
"test:integration": "vitest run tests/integration",
29+
"test:integration:watch": "vitest tests/integration",
30+
"test:all": "vitest run"
2631
},
2732
"keywords": [
2833
"firebase",
@@ -40,9 +45,14 @@
4045
"zod": "^3.24.1"
4146
},
4247
"devDependencies": {
43-
"typescript": "^5.7.3",
44-
"tsup": "^8.0.1",
48+
"@types/jsdom": "^21.1.7",
49+
"firebase": "^11.0.0",
50+
"jsdom": "^26.0.0",
4551
"prettier": "^3.1.1",
46-
"rimraf": "^6.0.1"
52+
"rimraf": "^6.0.1",
53+
"tsup": "^8.0.1",
54+
"typescript": "^5.7.3",
55+
"vite": "^6.2.0",
56+
"vitest": "^3.0.7"
4757
}
4858
}

packages/firebaseui-core/src/auth.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,9 @@ import {
1818
RecaptchaVerifier,
1919
AuthProvider,
2020
} from 'firebase/auth';
21-
import { FirebaseUIError } from './errors';
21+
import { handleFirebaseError } from './errors';
2222
import { type TranslationsConfig } from './translations';
2323

24-
async function handleFirebaseError(
25-
error: any,
26-
opts?: { language?: string; translations?: TranslationsConfig; enableHandleExistingCredential?: boolean }
27-
): Promise<never | UserCredential> {
28-
if (error?.code === 'auth/account-exists-with-different-credential' && opts?.enableHandleExistingCredential) {
29-
if (error.credential) {
30-
window.sessionStorage.setItem('pendingCred', JSON.stringify(error.credential));
31-
}
32-
33-
throw new FirebaseUIError(
34-
{
35-
code: 'auth/account-exists-with-different-credential',
36-
customData: {
37-
email: error.customData?.email,
38-
},
39-
},
40-
opts?.translations,
41-
opts?.language
42-
);
43-
}
44-
45-
// TODO: Debug why instanceof FirebaseError is not working
46-
if (error?.name === 'FirebaseError') {
47-
throw new FirebaseUIError(error, opts?.translations, opts?.language);
48-
}
49-
throw new FirebaseUIError({ code: 'unknown' }, opts?.translations, opts?.language);
50-
}
51-
5224
async function handlePendingCredential(user: UserCredential): Promise<UserCredential> {
5325
const pendingCredString = window.sessionStorage.getItem('pendingCred');
5426
if (!pendingCredString) return user;

packages/firebaseui-core/src/errors.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UserCredential } from 'firebase/auth';
12
import { ERROR_CODE_MAP, getTranslation, type TranslationsConfig } from './translations';
23

34
export class FirebaseUIError extends Error {
@@ -13,3 +14,31 @@ export class FirebaseUIError extends Error {
1314
this.code = errorCode;
1415
}
1516
}
17+
18+
export async function handleFirebaseError(
19+
error: any,
20+
opts?: { language?: string; translations?: TranslationsConfig; enableHandleExistingCredential?: boolean }
21+
): Promise<never | UserCredential> {
22+
if (error?.code === 'auth/account-exists-with-different-credential' && opts?.enableHandleExistingCredential) {
23+
if (error.credential) {
24+
window.sessionStorage.setItem('pendingCred', JSON.stringify(error.credential));
25+
}
26+
27+
throw new FirebaseUIError(
28+
{
29+
code: 'auth/account-exists-with-different-credential',
30+
customData: {
31+
email: error.customData?.email,
32+
},
33+
},
34+
opts?.translations,
35+
opts?.language
36+
);
37+
}
38+
39+
// TODO: Debug why instanceof FirebaseError is not working
40+
if (error?.name === 'FirebaseError') {
41+
throw new FirebaseUIError(error, opts?.translations, opts?.language);
42+
}
43+
throw new FirebaseUIError({ code: 'unknown' }, opts?.translations, opts?.language);
44+
}

0 commit comments

Comments
 (0)