From 05125175d54c3c828904b66f8b09834e09772f30 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 19 Dec 2019 14:10:11 -0400 Subject: [PATCH] require logoff to reauth --- services/gunDB/Mediator/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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,