Skip to content

Commit 7fe27b9

Browse files
fix(firebase): correct usage of FIREBASE_AUTH_OBJ_TS
1 parent d0c1287 commit 7fe27b9

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

src/modules/firebase/auth/app.auth.module.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { NgModule } from '@angular/core'
22
import { AngularFireAuthModule } from 'angularfire2/auth'
33
import { CookieService } from '../../cookies/browser'
44
import { FirebaseUniversalAuthService } from './browser.auth.service'
5+
import { makeStateKey } from '@angular/platform-browser'
56
import {
67
FIREBASE_AUTH_COOKIE_STO_KEY,
7-
FIREBASE_AUTH_COOKIE_FACTORY
8+
FIREBASE_AUTH_COOKIE_FACTORY,
9+
FIREBASE_AUTH_OBJ_TS
810
} from './tokens'
911

1012
// tslint:disable:no-this
@@ -15,7 +17,8 @@ import {
1517
providers: [
1618
FirebaseUniversalAuthService,
1719
{ provide: FIREBASE_AUTH_COOKIE_FACTORY, useClass: CookieService },
18-
{ provide: FIREBASE_AUTH_COOKIE_STO_KEY, useValue: 'firebaseJWT' }
20+
{ provide: FIREBASE_AUTH_COOKIE_STO_KEY, useValue: 'firebaseJWT' },
21+
{ provide: FIREBASE_AUTH_OBJ_TS, useValue: makeStateKey('fng.fb.auth.ts') }
1922
]
2023
})
2124
export class FirebaseAuthAppModule {}

src/modules/firebase/auth/browser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export { FirebaseUniversalAuthService } from './browser.auth.service'
12
export { FirebaseAuthBrowserModule } from './browser.auth.module'

src/modules/firebase/auth/server.auth.service.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { auth } from 'firebase-admin'
77
import { of } from 'rxjs'
88
import { flatMap, catchError, map, tap } from 'rxjs/operators'
9-
import { TransferState } from '@angular/platform-browser'
9+
import { TransferState, StateKey } from '@angular/platform-browser'
1010
import { FIREBASE_AUTH_OBJ_TS } from './tokens'
1111

1212
function validateToken(auth: auth.Auth, jwt: string) {
@@ -17,9 +17,9 @@ function byMappingItToUndefined(err: any) {
1717
return of(undefined)
1818
}
1919

20-
function cacheToBrowser(ts: TransferState) {
20+
function cacheToBrowser(tsCacheKey: StateKey<any>, ts: TransferState) {
2121
return function(obj: any) {
22-
ts.set(FIREBASE_AUTH_OBJ_TS, obj)
22+
ts.set(tsCacheKey, obj)
2323
}
2424
}
2525

@@ -42,6 +42,7 @@ function toPsuedoUserObject(jwtObj: any) {
4242
export class FirebaseServerAuth {
4343
constructor(
4444
private ts: TransferState,
45+
@Inject(FIREBASE_AUTH_OBJ_TS) private tsCacheKey: StateKey<any>,
4546
@Inject(FIREBASE_AUTH_SERVER_ADMIN_APP) private authAdmin: auth.Auth,
4647
@Inject(FIREBASE_AUTH_SERVER_USER_JWT) private jwt: string
4748
) {}
@@ -50,7 +51,7 @@ export class FirebaseServerAuth {
5051
? validateToken(this.authAdmin, this.jwt).pipe(
5152
flatMap(a => a),
5253
map(toPsuedoUserObject),
53-
tap(cacheToBrowser(this.ts)),
54+
tap(cacheToBrowser(this.tsCacheKey, this.ts)),
5455
catchError(byMappingItToUndefined)
5556
)
5657
: of(null)

src/modules/firebase/auth/tokens.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { ICookieGetSet } from './app.common'
22
import { InjectionToken } from '@angular/core'
3-
import { makeStateKey } from '@angular/platform-browser'
3+
import { StateKey } from '@angular/platform-browser'
44

55
export const FIREBASE_AUTH_COOKIE_FACTORY = new InjectionToken<ICookieGetSet>(
66
'fng.auth.ck.get.set'
77
)
88
export const FIREBASE_AUTH_COOKIE_STO_KEY = new InjectionToken<string>(
99
'fng.auth.ck.sto'
1010
)
11-
export const FIREBASE_AUTH_OBJ_TS = makeStateKey('fng.fb.auth.ts')
11+
export const FIREBASE_AUTH_OBJ_TS = new InjectionToken<StateKey<any>>(
12+
'fng.fb.auth.ts'
13+
)

0 commit comments

Comments
 (0)