require logoff to reauth

This commit is contained in:
Daniel Lugo 2019-12-19 14:10:11 -04:00
parent ed8f6d31fe
commit 05125175d5

View file

@ -146,6 +146,12 @@ const isRegistering = () => _isRegistering
*/ */
const authenticate = async (alias, pass) => { const authenticate = async (alias, pass) => {
if (isAuthenticated()) { 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 // move this to a subscription; implement off() ? todo
API.Jobs.onAcceptedRequests(user, mySEA) API.Jobs.onAcceptedRequests(user, mySEA)
return user._.sea.pub return user._.sea.pub
@ -188,6 +194,10 @@ const authenticate = async (alias, pass) => {
} }
} }
const logoff = () => {
user.leave()
}
const instantiateGun = async () => { const instantiateGun = async () => {
let mySecret = '' let mySecret = ''
@ -934,6 +944,7 @@ const getUser = () => {
module.exports = { module.exports = {
authenticate, authenticate,
logoff,
createMediator, createMediator,
isAuthenticated, isAuthenticated,
isAuthenticating, isAuthenticating,