move emailInfo, add unverifiedEmail
This commit is contained in:
parent
2aca926f2e
commit
a9f9f1c775
16
lib/index.js
16
lib/index.js
@ -83,10 +83,12 @@ PocketId.express = function (opts) {
|
|||||||
}
|
}
|
||||||
req.user.iss = scheme + "//" + iss.replace(/https?:\/\//, "");
|
req.user.iss = scheme + "//" + iss.replace(/https?:\/\//, "");
|
||||||
|
|
||||||
await addEmail(req).catch(function (err) {
|
var emailInfo = await addEmail(req).catch(function (err) {
|
||||||
// what to do with this error?
|
// what to do with this error?
|
||||||
console.warn("[pocketid.express.request-email] Error:", err);
|
console.warn("[pocketid.express.request-email] Error:", err);
|
||||||
});
|
});
|
||||||
|
Object.assign(req.user, emailInfo || {});
|
||||||
|
console.log("authz-user:", req.user);
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,8 +98,7 @@ PocketId.express = function (opts) {
|
|||||||
async function addEmail(req) {
|
async function addEmail(req) {
|
||||||
if (submails[req.user.sid]) {
|
if (submails[req.user.sid]) {
|
||||||
// TODO keep email cached longer than token expiration?
|
// TODO keep email cached longer than token expiration?
|
||||||
Object.assign(req.user, submails[req.user.sid]);
|
return submails[req.user.sid];
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp = await Request({
|
var resp = await Request({
|
||||||
@ -114,9 +115,14 @@ async function addEmail(req) {
|
|||||||
verifiedAt: result.verified_at,
|
verifiedAt: result.verified_at,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
|
return submails[req.user.sid];
|
||||||
}
|
}
|
||||||
Object.assign(req.user, submails[req.user.jit] || {});
|
if (result.unverified_email) {
|
||||||
console.log("authz-user:", req.user);
|
return {
|
||||||
|
unverifiedEmail: result.unverified_email,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
PocketId.refreshToken = function (opts) {
|
PocketId.refreshToken = function (opts) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user