automatically attempt sync if a user has an active session.
This commit is contained in:
parent
4bc1c1db75
commit
009a85f93e
|
@ -31,6 +31,9 @@ export class FastenDbService extends PouchdbRepository {
|
|||
constructor(private _httpClient: HttpClient) {
|
||||
const userIdentifier = localStorage.getItem("current_user")
|
||||
super(userIdentifier);
|
||||
if(userIdentifier){
|
||||
this.enableSync(userIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -173,14 +176,17 @@ export class FastenDbService extends PouchdbRepository {
|
|||
console.log("DB createIndex complete", createIndexMsg)
|
||||
|
||||
if(sync){
|
||||
console.log("DB sync init...", userIdentifier, this.getRemoteUserDb(userIdentifier))
|
||||
this.replicationHandler = this.localPouchDb.sync(this.getRemoteUserDb(userIdentifier))
|
||||
console.log("DB sync enabled")
|
||||
this.enableSync(userIdentifier)
|
||||
}
|
||||
|
||||
console.warn( "Configured PouchDB database for,", this.localPouchDb.name );
|
||||
return
|
||||
}
|
||||
private enableSync(userIdentifier: string){
|
||||
console.log("DB sync init...", userIdentifier, this.getRemoteUserDb(userIdentifier))
|
||||
this.replicationHandler = this.localPouchDb.sync(this.getRemoteUserDb(userIdentifier))
|
||||
console.log("DB sync enabled")
|
||||
}
|
||||
|
||||
private getRemoteUserDb(username: string){
|
||||
return `${this.remotePouchEndpoint}/userdb-${this.toHex(username)}`
|
||||
|
|
Loading…
Reference in New Issue