PouchDB + Superlogin + AngularJS 2 [英] PouchDB + Superlogin + AngularJS 2

查看:57
本文介绍了PouchDB + Superlogin + AngularJS 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试基于AngularJS 2编写CouchApp.显然,数据应该存储在CouchDB中. Web应用程序应该使用PouchDB从数据库中获取数据.对于身份验证,我考虑过使用Superlogin.

I am currently trying to write a CouchApp based on AngularJS 2. The data should obviously get stored in a CouchDB. The web app should get the data out of the DB using PouchDB. For authentication I thought about using Superlogin.

不幸的是,我无法弄清楚如何在ng2中使用PouchDB并使用Superlogin进行身份验证.此外,我什至不确定如果没有node.js服务器是否可以做所有这些事情.

Unfortunately I cannot figure out how to use PouchDB within ng2 and employ Superlogin for authentication. Furthermore, I am not even sure if it is possible to do all that without having a node.js server.

任何帮助/建议将不胜感激.谢谢.

Any help/advice will be appreciated. Thank you.

推荐答案

我刚刚创建了您提到的堆栈. 运行得很好,给我留下深刻的印象.

I've just created the stack you mentioned. Is working perfectly, I'm really impressed.

首先,我遵循了本教程(它是ionic2,但angular2逻辑完全相同):

First I've followed this tutorial (It's ionic2 but the angular2 logic is exactly the same) :

在Ionic 2中与PouchDB&进行离线同步; CouchDB

一旦运行,您可以按照其 Github存储库

Once this is working you can install superlogin following their Github repo

Superlogin必须本地安装以进行开发,并必须安装在云服务器中以用于生产.我的说明假定您已在本地安装它.

Superlogin has to be installed locally for development and in a cloud server for production use. My instruction assume that you have installed it locally.

像在超级登录回购中一样进行安装和测试后,您必须将超级登录-添加到您的angular2项目中.客户库.

Once installed and tested like in the superlogin repo, you have to add to your angular2 project the superlogin-client library.

我在将superlogin-client库插入angular2项目时遇到了一些问题,但是我找到了require的方法:

I had some problems to plug superlogin-client library to angular2 project but I've found a way with require :

npm install typings --global

还有

typings install dt~require --save --global

然后在Ionic2教程的todos提供程序中添加以下代码():

Then in the todos provider from Ionic2 tutorial you add this code () :

var config = {
  // The base URL for the SuperLogin routes with leading and trailing slashes (defaults to '/auth/')
  baseUrl: 'http://localhost:3000/auth/',
  // A list of API endpoints to automatically add the Authorization header to
  // By default the host the browser is pointed to will be added automatically
  endpoints: ["localhost:3000"],
  // Set this to true if you do not want the URL bar host automatically added to the list
  //noDefaultEndpoint: false,
  // Where to save your session token: localStorage ('local') or sessionStorage ('session'), default: 'local'
  storage: 'local',
  // The authentication providers that are supported by your SuperLogin host
  providers: ['facebook', 'twitter'],
  // Sets when to check if the session is expired. 'stateChange', 'startup' or nothing.
  // 'stateChange' checks every time $stateChangeStart or $routeChangeStart is fired
  // 'startup' checks just on app startup. If this is blank it will never check.
  checkExpired: 'stateChange',
  // A float that determines the percentage of a session duration, after which SuperLogin will automatically refresh the
  // token. For example if a token was issued at 1pm and expires at 2pm, and the threshold is 0.5, the token will
  // automatically refresh after 1:30pm. When authenticated, the token expiration is automatically checked on every
  // request. You can do this manually by calling superlogin.checkRefresh(). Default: 0.5
  refreshThreshold: 0.5
};

var superlogin = require('superlogin-client').default;
superlogin.configure(config)

多田 最后,您将能够在angular2项目中使用超级登录方法. 我希望我不要错过任何东西.

Tada Finally you'll be able to user superlogin methods in your angular2 project. I hope I don't miss anything.

PS.我一直在努力的一件事是超级登录配置,您必须知道用户名不喜欢大写字母!!!我正在成为MAD,已经创建了用户,但无法使用其用户名...

PS. One thing I've struggled with a bit is superlogin config, you have to know that username doesn't like capital letters!!! I was becoming MAD, my user was created but impossible to connect with its username...

如果您需要安装pouchdb插件:查看我的帖子

If you need to install pouchdb plugins : Check my post

祝你好运!

这篇关于PouchDB + Superlogin + AngularJS 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆