Fix jwt-token

This commit is contained in:
2025-09-17 18:30:35 +02:00
parent 98444a26cc
commit b96a06f48c

View File

@@ -7,35 +7,28 @@
module.exports = { module.exports = {
up: async (queryInterface, Sequelize) => { up: async (queryInterface, Sequelize) => {
try { // Check if the column already exists
// Check if tenants table exists first const tableDescription = await queryInterface.describeTable('tenants');
const tables = await queryInterface.showAllTables();
if (!tables.includes('tenants')) {
console.log('⚠️ Tenants table does not exist yet, skipping allow_registration migration...');
return;
}
await queryInterface.addColumn('tenants', 'allow_registration', {
type: Sequelize.BOOLEAN,
defaultValue: false, // Default to false for security
allowNull: false,
comment: 'Whether self-registration is allowed for local auth'
});
// For existing tenants, you might want to enable registration for specific tenants
// Uncomment the line below to enable registration for all existing tenants (NOT RECOMMENDED for production)
// await queryInterface.sequelize.query("UPDATE tenants SET allow_registration = true WHERE auth_provider = 'local'");
console.log('✅ Added allow_registration field to tenants table'); if (!tableDescription.allow_registration) {
console.log('⚠️ Registration is disabled by default for all tenants for security'); await queryInterface.addColumn('tenants', 'allow_registration', {
console.log('💡 To enable registration for a tenant, update the allow_registration field to true'); type: Sequelize.BOOLEAN,
} catch (error) { defaultValue: false, // Default to false for security
console.log('⚠️ Migration skipped - tables may not exist yet:', error.message); allowNull: false,
// Don't throw error, just skip this migration if tables don't exist comment: 'Whether self-registration is allowed for local auth'
} });
},
down: async (queryInterface, Sequelize) => { // For existing tenants, you might want to enable registration for specific tenants
// Uncomment the line below to enable registration for all existing tenants (NOT RECOMMENDED for production)
// await queryInterface.sequelize.query("UPDATE tenants SET allow_registration = true WHERE auth_provider = 'local'");
console.log('✅ Added allow_registration field to tenants table');
console.log('⚠️ Registration is disabled by default for all tenants for security');
console.log('💡 To enable registration for a tenant, update the allow_registration field to true');
} else {
console.log('⚠️ Column allow_registration already exists, skipping...');
}
}, down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn('tenants', 'allow_registration'); await queryInterface.removeColumn('tenants', 'allow_registration');
console.log('✅ Removed allow_registration field from tenants table'); console.log('✅ Removed allow_registration field from tenants table');
} }