Merge pull request #15 from shocknet/gundb-auth

require logoff to reauth
This commit is contained in:
Daniel Lugo 2019-12-19 14:34:49 -04:00 committed by GitHub
commit 838ae70aa6

View file

@ -146,6 +146,12 @@ const isRegistering = () => _isRegistering
*/
const authenticate = async (alias, pass) => {
if (isAuthenticated()) {
const currAlias = user.is && user.is.alias
if (alias !== currAlias) {
throw new Error(
`Tried to re-authenticate with an alias different to that of stored one, tried: ${alias} - stored: ${currAlias}, logoff first if need to change aliases.`
)
}
// move this to a subscription; implement off() ? todo
API.Jobs.onAcceptedRequests(user, mySEA)
return user._.sea.pub
@ -188,6 +194,10 @@ const authenticate = async (alias, pass) => {
}
}
const logoff = () => {
user.leave()
}
const instantiateGun = async () => {
let mySecret = ''
@ -934,6 +944,7 @@ const getUser = () => {
module.exports = {
authenticate,
logoff,
createMediator,
isAuthenticated,
isAuthenticating,