automatically attempt sync if a user has an active session.

This commit is contained in:
Jason Kulatunga 2022-10-08 22:53:30 -07:00
parent 4bc1c1db75
commit 009a85f93e
1 changed files with 9 additions and 3 deletions

View File

@ -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)}`