forked from koushik369mondal/WanderLust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugAuth.js
More file actions
53 lines (46 loc) · 1.81 KB
/
debugAuth.js
File metadata and controls
53 lines (46 loc) · 1.81 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 debugAuth() {
try {
await mongoose.connect(dbUrl);
// Check all users
const users = await User.find({});
console.log('All users in database:');
users.forEach(user => {
console.log(`- Username: ${user.username}, Email: ${user.email}, isAdmin: ${user.isAdmin}`);
});
// Test authentication with the admin user
if (users.length > 0) {
const admin = users.find(u => u.username === 'admin');
if (admin) {
console.log('\nTesting authentication...');
// Test with correct password
admin.authenticate('Admin123@', (err, user, passwordErr) => {
if (err) {
console.log('Authentication error:', err);
} else if (passwordErr) {
console.log('Password error:', passwordErr);
} else if (user) {
console.log('✅ Authentication successful!');
console.log('Use: Username: admin, Password: Admin123@');
} else {
console.log('❌ Authentication failed');
}
process.exit(0);
});
} else {
console.log('No admin user found');
process.exit(0);
}
} else {
console.log('No users found in database');
process.exit(0);
}
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}
debugAuth();