Hello I am a newbie here, I am developing an app using ionic 3 after following Josh’s tutorial part-2-creating-a-multiple-user-app-with-ionic-2-pouchdb-couchdb on how to use superlogin with ionic 2 the app is working Ok but I am unable to keep the user logged in after page refresh the user is logged out. From my research I am supposed to use superlogin-client to use the methods of superlogin but I have failed to implement this.
here is my todo.ts
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';
//import * as PouchDB from 'pouchdb';
import PouchDB from 'pouchdb';
import superlogin from 'superlogin-client';
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: false,
// 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
};
superlogin.configure(config);
@Injectable()
export class Todos {
data: any;
db: any;
remote: any;
constructor(private http: Http) {
}
init(details){
this.db = new PouchDB('zpos');
this.remote = details.userDBs.supertest;
let options = {
live: true,
retry: true,
continuous: true
};
this.db.sync(this.remote, options);
console.log(this.db);
}
logout(){
this.data = null;
this.db.destroy().then(() => {
console.log("database removed");
});
}
getTodos() {
if (this.data) {
return Promise.resolve(this.data);
}
return new Promise(resolve => {
this.db.allDocs({
include_docs: true
}).then((result) => {
this.data = [];
let doc = result.rows.map((row) => {
this.data.push(row.doc);
});
resolve(this.data);
this.db.changes({live: true, since: 'now', include_docs: true}).on('change', (change) => {
this.handleChange(change);
});
}).catch((error) => {
console.log(error);
});
});
}
createTodo(todo){
this.db.post(todo);
}
updateTodo(todo){
this.db.put(todo).catch((err) => {
console.log(err);
});
}
deleteTodo(todo){
this.db.remove(todo).catch((err) => {
console.log(err);
});
}
handleChange(change){
let changedDoc = null;
let changedIndex = null;
this.data.forEach((doc, index) => {
if(doc._id === change.id){
changedDoc = doc;
changedIndex = index;
}
});
//A document was deleted
if(change.deleted){
this.data.splice(changedIndex, 1);
}
else {
//A document was updated
if(changedDoc){
this.data[changedIndex] = change.doc;
}
//A document was added
else {
this.data.push(change.doc);
}
}
}
}
Any help I will really appreciate