Skip to content

Commit 6019cc5

Browse files
fix: extend cookie service
1 parent e6be0e3 commit 6019cc5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/modules/cookies/cookies.browser.service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@ import { Injectable } from '@angular/core'
22
import { Subject } from 'rxjs'
33
import { ICookieService, StringDict } from './common'
44
import { CookieAttributes, getJSON, remove, set } from 'js-cookie'
5+
import { filter } from 'rxjs/operators'
6+
7+
export interface KeyValue {
8+
readonly key: string
9+
readonly value: any
10+
}
511

612
// tslint:disable:no-this
713
// tslint:disable-next-line:no-class
814
@Injectable()
915
export class CookieService implements ICookieService {
1016
private readonly cookieSource = new Subject<StringDict>()
17+
private readonly changeSource = new Subject<KeyValue>()
18+
public readonly valueChange = this.changeSource.asObservable()
1119
public readonly valueChanges = this.cookieSource.asObservable()
1220

21+
targetValueChange(key: string) {
22+
return this.valueChange.pipe(filter(a => a && a.key === key))
23+
}
24+
1325
public set(name: string, value: any, opts?: CookieAttributes): void {
1426
set(name, value, opts)
1527
this.updateSource()
28+
this.broadcastChange(name)
1629
}
1730

1831
public remove(name: string, opts?: CookieAttributes): void {
1932
remove(name, opts)
2033
this.updateSource()
34+
this.broadcastChange(name)
2135
}
2236

2337
public get(name: string): any {
@@ -31,4 +45,11 @@ export class CookieService implements ICookieService {
3145
private updateSource() {
3246
this.cookieSource.next(this.getAll())
3347
}
48+
49+
private broadcastChange(key: string) {
50+
this.changeSource.next({
51+
key,
52+
value: this.get(key)
53+
})
54+
}
3455
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ function cacheToBrowser(ts: TransferState) {
2525

2626
function toPsuedoUserObject(jwtObj: any) {
2727
return {
28-
isAnonymous: false, // TODO
29-
uid: jwtObj.uid,
28+
isAnonymous: jwtObj.provider_id && jwtObj.provider_id === 'anonymous',
29+
uid: jwtObj.user_id,
3030
displayName: jwtObj.name,
3131
email: jwtObj.email,
3232
emailVerified: jwtObj.email_verified,
3333
photoURL: jwtObj.picture,
3434
phoneNumber: jwtObj.phone_number,
35-
// providerData: '',
3635
providerId: jwtObj.firebase && jwtObj.firebase.sign_in_provider
3736
}
3837
}

0 commit comments

Comments
 (0)