forked from koushik369mondal/WanderLust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeAdmin.js
More file actions
30 lines (25 loc) · 986 Bytes
/
makeAdmin.js
File metadata and controls
30 lines (25 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const mongoose = require('mongoose');
const User = require('./models/user');
const MONGO_URL = "mongodb://127.0.0.1:27017/wanderlust";
const dbUrl = process.env.ATLAS_DB_URL || MONGO_URL;
async function makeAdmin() {
try {
await mongoose.connect(dbUrl);
// Find any existing user and make them admin
const existingUser = await User.findOne({});
if (existingUser) {
existingUser.isAdmin = true;
await existingUser.save();
console.log(`✅ Made ${existingUser.username} an admin!`);
console.log(`Login with username: ${existingUser.username}`);
} else {
console.log('No users found. Please signup first at http://localhost:8080/signup');
console.log('Then run this script again to make that user an admin.');
}
process.exit(0);
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}
makeAdmin();