Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Couchdb创建PockDB身份验证_Javascript_Angular_Ionic Framework_Couchdb_Pouchdb - Fatal编程技术网

Javascript 使用Couchdb创建PockDB身份验证

Javascript 使用Couchdb创建PockDB身份验证,javascript,angular,ionic-framework,couchdb,pouchdb,Javascript,Angular,Ionic Framework,Couchdb,Pouchdb,我正在尝试创建一个具有couchdb@2.X及pouchdb@6.4.2,我正在努力用每个用户的db来制作身份验证代码,我理解了一般的想法(有点),并试图搜索一个示例或修复我的代码,以下是我迄今为止所做的: import { Injectable } from '@angular/core'; import PouchDB from 'pouchdb'; import PouchAuth from 'pouchdb-authentication'; import { syncResult }

我正在尝试创建一个具有couchdb@2.X及pouchdb@6.4.2,我正在努力用每个用户的db来制作身份验证代码,我理解了一般的想法(有点),并试图搜索一个示例或修复我的代码,以下是我迄今为止所做的:

import { Injectable } from '@angular/core';
import PouchDB from 'pouchdb';
import  PouchAuth  from 'pouchdb-authentication';
import { syncResult } from './../../models/syncResult'
import { credentials } from '../../models/credentials';
PouchDB.plugin(PouchAuth);

/*
  Generated class for the PouchDbServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class PouchDbServiceProvider {

  url:any;
  private localDB: any;
  private remoteDB:any;
  username: string;
  password: string;
  constructor(private pendingSync: Promise<syncResult>) {
  }


  singUp(user,pass){
    this.teardown();

    let options = {
      live:true,
      retry:true,
      continuous:true,
      auth:{
        username: user,
        password: pass
      }
    }

    this.localDB = new PouchDB(this.getDBname(user));
    this.remoteDB = new PouchDB('http://localhost:5984/'+this.getDBname(user),options);
    this.localDB.sync(this.remoteDB,options);
  }

  private getDBname(userIdentifier:string){
    var dbName = userIdentifier.toLowerCase().replace(/[^a-z0-9_$()+-]/g, "-");
    return (dbName);
  }

  public teardown(){

    if(!this.localDB){
      return;
    }
    this.localDB.close();
    this.localDB = null;
    this.remoteDB.close();
    this.remoteDB = null;
  }

我知道有很多错误,但我找不到最近的帮助,我看到的所有帖子都是旧的或没有明确的文档记录(或者我很愚蠢,如果这个选项,请告诉我正确的方法哈哈)

PS:我看了couchdb文档,明白它在说什么,但不知道如何编码这个想法
    Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[PouchDbServiceProvider -> t]: 
  StaticInjectorError(Platform: core)[PouchDbServiceProvider -> t]: 
    NullInjectorError: No provider for t!
Error: StaticInjectorError(AppModule)[PouchDbServiceProvider -> t]: 
  StaticInjectorError(Platform: core)[PouchDbServiceProvider -> t]: 
    NullInjectorError: No provider for t!
    at _NullInjector.get (http://localhost:8100/build/vendor.js:1377:19)
    at resolveToken (http://localhost:8100/build/vendor.js:1675:24)
    at tryResolveToken (http://localhost:8100/build/vendor.js:1617:16)
    at StaticInjector.get (http://localhost:8100/build/vendor.js:1485:20)
    at resolveToken (http://localhost:8100/build/vendor.js:1675:24)
    at tryResolveToken (http://localhost:8100/build/vendor.js:1617:16)
    at StaticInjector.get (http://localhost:8100/build/vendor.js:1485:20)
    at resolveNgModuleDep (http://localhost:8100/build/vendor.js:11270:25)
    at _createClass (http://localhost:8100/build/vendor.js:11307:29)
    at _createProviderInstance$1 (http://localhost:8100/build/vendor.js:11281:26)
    at c (http://localhost:8100/build/polyfills.js:3:19752)
    at Object.reject (http://localhost:8100/build/polyfills.js:3:19174)
    at NavControllerBase._fireError (http://localhost:8100/build/vendor.js:51765:16)
    at NavControllerBase._failed (http://localhost:8100/build/vendor.js:51758:14)
    at http://localhost:8100/build/vendor.js:51805:59
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14976)
    at Object.onInvoke (http://localhost:8100/build/vendor.js:5134:33)
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14916)
    at r.run (http://localhost:8100/build/polyfills.js:3:10143)
    at http://localhost:8100/build/polyfills.js:3:20242