Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const authorizationId = v4();
// Get the credential
let credential = await authority.credential(tx, token.sub);
// Try to associate an existing user by email.
if (
!credential &&
authority.details.emailAuthorityId &&
authority.details.matchesUsersByEmail &&
token.email &&
token.email_verified
) {
const emailAuthority = await EmailAuthority.read(
tx,
authority.details.emailAuthorityId
);
const emailCredential =
emailAuthority &&
emailAuthority.enabled &&
(await emailAuthority.credential(tx, token.email));
if (emailCredential && emailCredential.enabled) {
credential = await OpenIdCredential.write(
tx,
{
enabled: true,
id: v4(),
userId: emailCredential.userId,
public async emailAuthority(
tx: PoolClient,
refresh?: boolean
): Promise {
if (!refresh && this._emailAuthority) {
return this._emailAuthority;
}
if (!this.details.emailAuthorityId) {
return null;
}
return (this._emailAuthority = EmailAuthority.read(
tx,
this.details.emailAuthorityId
));
}