Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
auth.then(res => {
console.groupCollapsed("authenticate"); // groupCollapsed
console.log(event);
this.authenticated = res.authenticate;
this.linked = res.link;
if (this.linked) {
this.otp = new OTPAuth.HOTP({
issuer: "Beet",
label: "BeetAuth",
algorithm: "SHA1",
digits: 32,
counter: 0,
secret: OTPAuth.Secret.fromHex(this.identity.secret)
});
console.debug("otp instantiated", this.identity.secret.toString());
this.identity = Object.assign(this.identity, res.requested);
} else {
this.beetkey = res.pub_key;
}
console.groupEnd();
resolve(res);
}).catch(rej => {
console.error("socket.onopen authenticate rejected", rej);
console.log(res);
this.chain = res.chain;
if (res.existing) {
this.identityhash = res.identityhash;
try {
this.identity = await BeetClientDB.apps.where("identityhash").equals(this.identityhash).first();
console.debug("app fetched", this.identity);
this.authenticated = res.authenticate;
this.linked = res.link;
this.otp = new OTPAuth.HOTP({
issuer: "Beet",
label: "BeetAuth",
algorithm: "SHA1",
digits: 32,
counter: 0,
secret: OTPAuth.Secret.fromHex(this.identity.secret)
});
this.identity = Object.assign(this.identity, res.requested);
console.groupEnd();
resolve(this.identityhash);
} catch (e) {
console.warn("Beet has found an established identity, but the client does not know it, requesting relink ...");
console.groupEnd();
try {
let relink = await this.link(chain, requestDetails, res.identityhash);
resolve(relink);
}catch(e){
reject(e);
}
}
} else {
this.identityhash = res.identityhash;