-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-admin.js
More file actions
79 lines (67 loc) · 2.73 KB
/
setup-admin.js
File metadata and controls
79 lines (67 loc) · 2.73 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
const auth = admin.auth();
async function setupAdmin() {
console.log('Firebase Project ID:', admin.app().options.projectId);
console.log('Starting admin setup...\n');
try {
// Create new admin user with email and password
const newAdmin = await auth.createUser({
email: 'superadmin@wingzone.com',
password: 'WingZone2026!',
displayName: 'Super Admin',
emailVerified: true // Set as verified so no email confirmation needed
});
console.log('✓ Admin user created with UID:', newAdmin.uid);
console.log('✓ Email:', newAdmin.email);
console.log('✓ Email Verified:', newAdmin.emailVerified);
// Set admin role in Firestore
await db.collection('users').doc(newAdmin.uid).set({
email: 'superadmin@wingzone.com',
role: 'admin',
displayName: 'Super Admin',
createdAt: admin.firestore.FieldValue.serverTimestamp()
});
console.log('✓ Admin role set in Firestore!');
console.log('\n=================================');
console.log('Admin Login Credentials:');
console.log('Email: superadmin@wingzone.com');
console.log('Password: WingZone2026!');
console.log('=================================\n');
process.exit(0);
} catch (error) {
if (error.code === 'auth/email-already-exists') {
console.log('⚠ User already exists. Updating password and admin role...');
const existingUser = await auth.getUserByEmail('superadmin@wingzone.com');
console.log('Found existing user with UID:', existingUser.uid);
// Update password
await auth.updateUser(existingUser.uid, {
password: 'WingZone2026!',
emailVerified: true
});
console.log('✓ Password updated!');
// Update role in Firestore
await db.collection('users').doc(existingUser.uid).set({
email: 'superadmin@wingzone.com',
role: 'admin',
displayName: 'Super Admin',
createdAt: admin.firestore.FieldValue.serverTimestamp()
}, { merge: true });
console.log('✓ Admin role updated in Firestore!');
console.log('\n=================================');
console.log('Admin Login Credentials:');
console.log('Email: superadmin@wingzone.com');
console.log('Password: WingZone2026!');
console.log('=================================\n');
} else {
console.error('Error:', error);
}
process.exit(error.code === 'auth/email-already-exists' ? 0 : 1);
}
}
setupAdmin();
// To run this script: uses the node command, use the terminal