Merge pull request #326 from shocknet/auth-check

check that alias and pass are populated strings
This commit is contained in:
CapDog 2021-04-04 11:20:33 -04:00 committed by GitHub
commit 2948cbccd4

View file

@ -1,6 +1,7 @@
/** /**
* @format * @format
*/ */
const Common = require('shock-common')
const Gun = require('gun') const Gun = require('gun')
// @ts-ignore // @ts-ignore
require('gun/nts') require('gun/nts')
@ -308,6 +309,16 @@ const getUser = () => {
* @returns {Promise<string>} * @returns {Promise<string>}
*/ */
const authenticate = async (alias, pass, __user) => { const authenticate = async (alias, pass, __user) => {
if (!Common.isPopulatedString(alias)) {
throw new TypeError(
`Expected alias to be a populated string, instead got: ${alias}`
)
}
if (!Common.isPopulatedString(pass)) {
throw new TypeError(
`Expected pass to be a populated string, instead got: ${pass}`
)
}
const _user = __user || user const _user = __user || user
const isFreshGun = _user !== user const isFreshGun = _user !== user
if (isFreshGun) { if (isFreshGun) {