Created
June 13, 2017 15:50
-
-
Save michsch/2ec7a714cc5f79b525d68ebd20b20700 to your computer and use it in GitHub Desktop.
hoodie authentication problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"address": "127.0.0.1", | |
"port": 8080, | |
"data": ".hoodie", | |
"public": "public", | |
"dbUrl": "http://admin:[email protected]:5984/prototype", | |
"adminPassword": "admin", | |
"dbAdapter": "pouchdb-adapter-fs", | |
"inMemory": false, | |
"loglevel": "warn", | |
"url": "http://admin:[email protected]:5984" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sha256 from 'sha256' | |
import PouchDB from 'pouchdb' | |
const Hoodie = require('@hoodie/client') | |
const hoodie = new Hoodie({ | |
url: 'http://127.0.0.1:8080', | |
PouchDB: PouchDB | |
}) | |
const store = hoodie.store | |
export const register = function (username, preferred_name, password) { | |
return new Promise ((resolve, reject) => { | |
hoodie.account.signUp({ username, password }).then(() => { | |
return store.add({ | |
_id: 'user-data/' + sha256(username), | |
email: username, | |
preferred_name: preferred_name | |
}) | |
}).then((userData) => { | |
console.log('registration', userData) | |
resolve(userData) | |
}) | |
.catch((error) => { | |
console.error('error', username, error) | |
reject(error) | |
}) | |
}) | |
} | |
export const login = (username, password) => { | |
return new Promise((resolve, reject) => { | |
hoodie.account.signIn({ username, password }) | |
.then((user) => { | |
return store.find('user-data/' + sha256(user.username)) | |
}) | |
.then((userData) => { | |
console.log('login', userData) | |
resolve(userData) | |
}) | |
.catch((error) => { | |
console.error('error', error) | |
reject(error) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment