diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index c9329b59..be27bf87 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -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,