Fix isEmail validation failure on valid emails during Docker setup (#835)

This commit is contained in:
Chris 2026-02-11 15:42:11 +02:00 committed by GitHub
parent 2ce1c62c48
commit 5a1f0650ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View file

@ -96,6 +96,8 @@ else
fi
if [ -n "${TUDUDI_USER_EMAIL:-}" ] && [ -n "${TUDUDI_USER_PASSWORD:-}" ]; then
# Trim whitespace/carriage returns that may come from docker-compose env vars
TUDUDI_USER_EMAIL=$(printf '%s' "$TUDUDI_USER_EMAIL" | tr -d '[:space:]')
node scripts/user-create.js "$TUDUDI_USER_EMAIL" "$TUDUDI_USER_PASSWORD" true || exit 1
fi

View file

@ -237,6 +237,9 @@ module.exports = (sequelize) => {
tableName: 'users',
hooks: {
beforeValidate: async (user) => {
if (user.email) {
user.email = user.email.trim().toLowerCase();
}
if (user.password) {
user.password_digest = await bcrypt.hash(
user.password,

View file

@ -11,12 +11,13 @@ const _ = require('lodash');
* @returns {Promise<{user: User, created: boolean}>} User object and creation status
*/
async function createOrUpdateUser(email, password) {
const normalizedEmail = email.trim().toLowerCase();
const hashedPassword = await bcrypt.hash(password, 10);
const [user, created] = await User.findOrCreate({
where: { email },
where: { email: normalizedEmail },
defaults: {
email,
email: normalizedEmail,
password_digest: hashedPassword,
},
});