mirror of
https://github.com/hanzoai/chat.git
synced 2026-09-30 20:51:17 +00:00
- Added HanzoIAMSSOHandler class for Hanzo IAM authentication - Integrated Hanzo IAM as an SSO provider alongside Google, Microsoft, and generic SSO - Updated login UI from 'LiteLLM' to 'Hanzo Router' branding - Changed error messages to reference Hanzo Router instead of LiteLLM - Added .env.hanzo-iam.example configuration file - Updated environment variable from LITELLM_MASTER_KEY to ROUTER_MASTER_KEY (with backward compatibility) - Added support for HANZO_IAM_CLIENT_ID, HANZO_IAM_CLIENT_SECRET, and HANZO_IAM_SERVER_URL - Maintained compatibility with existing authentication methods (built-in auth and other SSO providers)
80 lines
2.0 KiB
JavaScript
80 lines
2.0 KiB
JavaScript
const bcrypt = require('bcryptjs');
|
|
const { MongoClient } = require('mongodb');
|
|
|
|
async function createDemoUsers() {
|
|
const uri = 'mongodb://hanzo:hanzo123@localhost:27017/HanzoChat?authSource=admin';
|
|
const client = new MongoClient(uri);
|
|
|
|
try {
|
|
await client.connect();
|
|
console.log('Connected to MongoDB');
|
|
|
|
const db = client.db('HanzoChat');
|
|
const usersCollection = db.collection('users');
|
|
|
|
// Demo users
|
|
const demoUsers = [
|
|
{
|
|
email: '[email protected]',
|
|
username: 'admin',
|
|
name: 'Hanzo Admin',
|
|
password: 'demo1234',
|
|
role: 'ADMIN',
|
|
},
|
|
{
|
|
email: '[email protected]',
|
|
username: 'hattori',
|
|
name: 'Hattori Hanzo',
|
|
password: 'demo1234',
|
|
role: 'USER',
|
|
},
|
|
{
|
|
email: '[email protected]',
|
|
username: 'demo',
|
|
name: 'Demo User',
|
|
password: 'demo1234',
|
|
role: 'USER',
|
|
}
|
|
];
|
|
|
|
for (const user of demoUsers) {
|
|
// Check if user already exists
|
|
const existingUser = await usersCollection.findOne({ email: user.email });
|
|
|
|
if (existingUser) {
|
|
console.log(`User ${user.email} already exists, skipping...`);
|
|
continue;
|
|
}
|
|
|
|
// Hash password
|
|
const hashedPassword = await bcrypt.hash(user.password, 10);
|
|
|
|
// Create user document
|
|
const userDoc = {
|
|
email: user.email,
|
|
username: user.username,
|
|
name: user.name,
|
|
password: hashedPassword,
|
|
role: user.role,
|
|
isVerified: true,
|
|
emailVerified: true,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
refreshToken: [],
|
|
plugins: [],
|
|
avatar: null,
|
|
};
|
|
|
|
const result = await usersCollection.insertOne(userDoc);
|
|
console.log(`Created user: ${user.email} with ID: ${result.insertedId}`);
|
|
}
|
|
|
|
console.log('Demo users created successfully!');
|
|
} catch (error) {
|
|
console.error('Error creating demo users:', error);
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|
|
|
|
createDemoUsers(); |