Skip to content

Commit e7926b7

Browse files
committed
feat: add new policy provider
1 parent 1d94dde commit e7926b7

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

packages/angular/projects/firebaseui-angular/src/lib/provider.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,26 @@ import {
77
inject,
88
} from '@angular/core';
99
import { FirebaseApps } from '@angular/fire/app';
10-
import { type FirebaseUI as FirebaseUIType, getTranslation } from '@firebase-ui/core';
10+
import {
11+
type FirebaseUI as FirebaseUIType,
12+
getTranslation,
13+
} from '@firebase-ui/core';
1114
import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators';
1215
import { Observable, ReplaySubject } from 'rxjs';
1316
import { Store } from 'nanostores';
1417
import { TranslationCategory, TranslationKey } from '@firebase-ui/translations';
1518

16-
const FIREBASE_UI_STORE = new InjectionToken<FirebaseUIType>('firebaseui.store');
19+
const FIREBASE_UI_STORE = new InjectionToken<FirebaseUIType>(
20+
'firebaseui.store',
21+
);
22+
const FIREBASE_UI_POLICIES = new InjectionToken<PolicyConfig>(
23+
'firebaseui.policies',
24+
);
25+
26+
type PolicyConfig = {
27+
termsOfServiceUrl: string;
28+
privacyPolicyUrl: string;
29+
};
1730

1831
export function provideFirebaseUI(
1932
uiFactory: (apps: FirebaseApps) => FirebaseUIType,
@@ -27,6 +40,14 @@ export function provideFirebaseUI(
2740
return makeEnvironmentProviders(providers);
2841
}
2942

43+
export function provideFirebaseUIPolicies(factory: () => PolicyConfig) {
44+
const providers: Provider[] = [
45+
{ provide: FIREBASE_UI_POLICIES, useFactory: factory },
46+
];
47+
48+
return makeEnvironmentProviders(providers);
49+
}
50+
3051
@Injectable({
3152
providedIn: 'root',
3253
})
@@ -43,9 +64,7 @@ export class FirebaseUI {
4364
key: TranslationKey<T>,
4465
) {
4566
return this.config().pipe(
46-
map((config) =>
47-
getTranslation(config, category, key),
48-
),
67+
map((config) => getTranslation(config, category, key)),
4968
);
5069
}
5170

@@ -61,3 +80,18 @@ export class FirebaseUI {
6180
this.destroyed$.complete();
6281
}
6382
}
83+
84+
@Injectable({
85+
providedIn: 'root',
86+
})
87+
export class FirebaseUIPolicies {
88+
private policies = inject(FIREBASE_UI_POLICIES);
89+
90+
get termsOfServiceUrl() {
91+
return this.policies.termsOfServiceUrl;
92+
}
93+
94+
get privacyPolicyUrl() {
95+
return this.policies.privacyPolicyUrl;
96+
}
97+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { InjectionToken } from '@angular/core';
2+
3+
export interface PolicyConfig {
4+
termsOfServiceUrl: string;
5+
privacyPolicyUrl: string;
6+
}
7+
8+
export const POLICY_CONFIG = new InjectionToken<PolicyConfig>('PolicyConfig');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// src/app/policies/providePolicies.ts
2+
import { Provider } from '@angular/core';
3+
import { POLICY_CONFIG, PolicyConfig } from './policy.config';
4+
5+
export function providePolicies(): Provider {
6+
return {
7+
provide: POLICY_CONFIG,
8+
useValue: {
9+
termsOfServiceUrl: 'https://yourdomain.com/terms',
10+
privacyPolicyUrl: 'https://yourdomain.com/privacy',
11+
} satisfies PolicyConfig,
12+
};
13+
}

0 commit comments

Comments
 (0)