Browse Source

fix: invalidate token if admin email or password changed

- Invalidate old token if admin email changed in env
- Invalidate token if password updated in env
- Avoid unnecessary update if both email and passwords are same

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2393/head
Pranav C 2 years ago
parent
commit
bcd3c9ee50
  1. 33
      packages/nocodb/src/lib/meta/api/userApi/initAdminFromEnv.ts

33
packages/nocodb/src/lib/meta/api/userApi/initAdminFromEnv.ts

@ -169,7 +169,8 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) {
salt, salt,
email, email,
password, password,
email_verification_token email_verification_token,
token_version: null
}, },
ncMeta ncMeta
); );
@ -181,22 +182,32 @@ export default async function initAdminFromEnv(_ncMeta = Noco.ncMeta) {
salt, salt,
email, email,
password, password,
email_verification_token email_verification_token,
token_version: null
}, },
ncMeta ncMeta
); );
} }
} else { } else {
// if email's are not different update the password and hash const newPasswordHash = await promisify(bcrypt.hash)(
await User.update( process.env.NC_ADMIN_PASSWORD,
superUser.id, superUser.hash
{
salt,
password,
email_verification_token
},
ncMeta
); );
if (newPasswordHash !== superUser.password) {
// if email's are same and passwords are different
// then update the password and token version
await User.update(
superUser.id,
{
salt,
password,
email_verification_token,
token_version: null
},
ncMeta
);
}
} }
} }
await ncMeta.commit(); await ncMeta.commit();

Loading…
Cancel
Save