-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-complete-flow.html
More file actions
392 lines (337 loc) · 16.4 KB
/
test-complete-flow.html
File metadata and controls
392 lines (337 loc) · 16.4 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Complete Flow Test - IGNITE Part Share</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
}
.test-section {
margin: 20px 0;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
.status {
padding: 10px;
margin: 10px 0;
border-radius: 5px;
}
.success { background-color: #d4edda; color: #155724; }
.error { background-color: #f8d7da; color: #721c24; }
.info { background-color: #d1ecf1; color: #0c5460; }
.warning { background-color: #fff3cd; color: #856404; }
button {
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.btn-primary { background-color: #007bff; color: white; }
.btn-success { background-color: #28a745; color: white; }
.btn-warning { background-color: #ffc107; color: black; }
.btn-danger { background-color: #dc3545; color: white; }
.flow-step {
margin: 10px 0;
padding: 10px;
background-color: #f8f9fa;
border-left: 4px solid #007bff;
}
.step-complete { border-left-color: #28a745; }
.step-pending { border-left-color: #ffc107; }
.step-error { border-left-color: #dc3545; }
</style>
</head>
<body>
<h1>Complete Authentication Flow Test</h1>
<div id="status"></div>
<div class="test-section">
<h2>Step 1: Firebase Connection</h2>
<div id="firebase-status" class="flow-step step-pending">
<strong>Firebase SDK:</strong> Checking...
</div>
<div id="auth-status" class="flow-step step-pending">
<strong>Authentication Service:</strong> Checking...
</div>
<div id="firestore-status" class="flow-step step-pending">
<strong>Firestore Database:</strong> Checking...
</div>
<div id="storage-status" class="flow-step step-pending">
<strong>Firebase Storage:</strong> Checking...
</div>
</div>
<div class="test-section">
<h2>Step 2: Authentication Flow</h2>
<div id="auth-flow-status" class="flow-step step-pending">
<strong>Current Status:</strong> <span id="current-auth-status">Checking...</span>
</div>
<div id="user-info" style="display: none;">
<p><strong>User Email:</strong> <span id="user-email"></span></p>
<p><strong>User ID:</strong> <span id="user-id"></span></p>
<p><strong>FIRST Verified:</strong> <span id="first-verified"></span></p>
</div>
<button class="btn-primary" onclick="testLogin()">Test Login</button>
<button class="btn-warning" onclick="testLogout()">Test Logout</button>
</div>
<div class="test-section">
<h2>Step 3: Profile Management</h2>
<div id="profile-status" class="flow-step step-pending">
<strong>Profile Access:</strong> Checking...
</div>
<button class="btn-success" onclick="testProfileAccess()">Test Profile Access</button>
<button class="btn-primary" onclick="testTeamCreation()">Test Team Creation</button>
</div>
<div class="test-section">
<h2>Step 4: FIRST Verification</h2>
<div id="verification-status" class="flow-step step-pending">
<strong>Verification Status:</strong> Checking...
</div>
<button class="btn-primary" onclick="testVerification()">Test Verification</button>
</div>
<div class="test-section">
<h2>Step 5: Protected Features</h2>
<div id="protected-features-status" class="flow-step step-pending">
<strong>Protected Features Access:</strong> Checking...
</div>
<button class="btn-success" onclick="testProtectedFeatures()">Test Protected Features</button>
</div>
<div id="results"></div>
<!-- Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-firestore-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-storage-compat.js"></script>
<!-- Firebase Config -->
<script src="firebase-config.js"></script>
<!-- Auth Script -->
<script src="auth.js"></script>
<script>
let testResults = [];
function showStatus(message, type = 'info') {
const statusDiv = document.getElementById('status');
statusDiv.innerHTML = `<div class="status ${type}">${message}</div>`;
}
function addResult(message, type = 'info') {
const resultsDiv = document.getElementById('results');
const div = document.createElement('div');
div.className = `status ${type}`;
div.textContent = message;
resultsDiv.appendChild(div);
testResults.push({ message, type });
}
function updateStepStatus(stepId, status, message) {
const step = document.getElementById(stepId);
step.className = `flow-step step-${status}`;
step.innerHTML = `<strong>${step.querySelector('strong').textContent}</strong> ${message}`;
}
// Test Firebase connection
window.addEventListener('load', function() {
testFirebaseConnection();
});
async function testFirebaseConnection() {
try {
// Test Firebase SDK
if (typeof firebase !== 'undefined') {
updateStepStatus('firebase-status', 'complete', '✅ Loaded successfully');
} else {
updateStepStatus('firebase-status', 'error', '❌ Not loaded');
return;
}
// Test Auth
if (auth) {
updateStepStatus('auth-status', 'complete', '✅ Initialized');
} else {
updateStepStatus('auth-status', 'error', '❌ Not initialized');
}
// Test Firestore
if (db) {
updateStepStatus('firestore-status', 'complete', '✅ Initialized');
} else {
updateStepStatus('firestore-status', 'error', '❌ Not initialized');
}
// Test Storage
if (firebase.storage) {
updateStepStatus('storage-status', 'complete', '✅ Available');
} else {
updateStepStatus('storage-status', 'error', '❌ Not available');
}
// Check auth state
auth.onAuthStateChanged(function(user) {
if (user) {
updateStepStatus('auth-flow-status', 'complete', '✅ User signed in');
document.getElementById('current-auth-status').textContent = 'Signed In';
document.getElementById('user-info').style.display = 'block';
document.getElementById('user-email').textContent = user.email;
document.getElementById('user-id').textContent = user.uid;
// Check FIRST verification
checkFirstVerificationStatus().then(verified => {
document.getElementById('first-verified').textContent = verified ? 'Yes' : 'No';
});
} else {
updateStepStatus('auth-flow-status', 'pending', '⏳ No user signed in');
document.getElementById('current-auth-status').textContent = 'Not Signed In';
document.getElementById('user-info').style.display = 'none';
}
});
} catch (error) {
addResult('❌ Firebase connection test failed: ' + error.message, 'error');
}
}
async function testLogin() {
try {
addResult('ℹ️ Testing login functionality...', 'info');
// Test with a dummy account (this won't actually log in)
const email = 'test@example.com';
const password = 'testpassword';
try {
await auth.signInWithEmailAndPassword(email, password);
addResult('✅ Login function works (though credentials are invalid)', 'success');
} catch (error) {
if (error.code === 'auth/user-not-found' || error.code === 'auth/wrong-password') {
addResult('✅ Login function works correctly (expected error for invalid credentials)', 'success');
} else {
addResult('❌ Login function error: ' + error.message, 'error');
}
}
} catch (error) {
addResult('❌ Login test failed: ' + error.message, 'error');
}
}
async function testLogout() {
try {
addResult('ℹ️ Testing logout functionality...', 'info');
if (auth.currentUser) {
await auth.signOut();
addResult('✅ Logout successful', 'success');
} else {
addResult('ℹ️ No user to log out', 'info');
}
} catch (error) {
addResult('❌ Logout test failed: ' + error.message, 'error');
}
}
async function testProfileAccess() {
try {
addResult('ℹ️ Testing profile access...', 'info');
if (!auth.currentUser) {
addResult('⚠️ No user signed in - profile access would redirect to login', 'warning');
return;
}
// Test if profile functions are available
if (typeof getUserProfile === 'function') {
addResult('✅ Profile functions available', 'success');
// Test getting user profile
const profile = await getUserProfile(auth.currentUser.uid);
if (profile) {
addResult('✅ User profile retrieved successfully', 'success');
} else {
addResult('ℹ️ No existing profile found (this is normal for new users)', 'info');
}
} else {
addResult('❌ Profile functions not available', 'error');
}
} catch (error) {
addResult('❌ Profile access test failed: ' + error.message, 'error');
}
}
async function testTeamCreation() {
try {
addResult('ℹ️ Testing team creation...', 'info');
if (!auth.currentUser) {
addResult('⚠️ No user signed in - team creation requires authentication', 'warning');
return;
}
// Test if team functions are available
if (typeof db !== 'undefined') {
addResult('✅ Database available for team creation', 'success');
// Test creating a test team
const testTeam = {
name: 'Test Team',
number: '9999',
location: 'Test Location',
school: 'Test School',
description: 'Test team for verification',
createdBy: auth.currentUser.uid,
createdAt: new Date(),
updatedAt: new Date()
};
try {
const docRef = await db.collection('teams').add(testTeam);
addResult('✅ Test team created successfully with ID: ' + docRef.id, 'success');
// Clean up - delete the test team
await docRef.delete();
addResult('✅ Test team cleaned up', 'success');
} catch (error) {
addResult('❌ Team creation failed: ' + error.message, 'error');
}
} else {
addResult('❌ Database not available', 'error');
}
} catch (error) {
addResult('❌ Team creation test failed: ' + error.message, 'error');
}
}
async function testVerification() {
try {
addResult('ℹ️ Testing FIRST verification...', 'info');
if (!auth.currentUser) {
addResult('⚠️ No user signed in - verification requires authentication', 'warning');
return;
}
// Test if verification functions are available
if (typeof db !== 'undefined' && typeof firebase.storage !== 'undefined') {
addResult('✅ Verification services available', 'success');
// Test verification status check
const userProfile = await getUserProfile(auth.currentUser.uid);
if (userProfile && userProfile.firstVerificationStatus) {
addResult('ℹ️ Current verification status: ' + userProfile.firstVerificationStatus, 'info');
} else {
addResult('ℹ️ No verification status found (user needs to submit verification)', 'info');
}
} else {
addResult('❌ Verification services not available', 'error');
}
} catch (error) {
addResult('❌ Verification test failed: ' + error.message, 'error');
}
}
async function testProtectedFeatures() {
try {
addResult('ℹ️ Testing protected features access...', 'info');
if (!auth.currentUser) {
addResult('⚠️ No user signed in - protected features require authentication', 'warning');
return;
}
// Test if requireAuth function is available
if (typeof requireAuth === 'function') {
addResult('✅ Access control function available', 'success');
// Test access control
const hasAccess = requireAuth('test-action');
if (hasAccess) {
addResult('✅ User has access to protected features', 'success');
} else {
addResult('⚠️ User does not have access (may need FIRST verification)', 'warning');
}
} else {
addResult('❌ Access control function not available', 'error');
}
} catch (error) {
addResult('❌ Protected features test failed: ' + error.message, 'error');
}
}
// Summary function
function showSummary() {
const successCount = testResults.filter(r => r.type === 'success').length;
const errorCount = testResults.filter(r => r.type === 'error').length;
const warningCount = testResults.filter(r => r.type === 'warning').length;
addResult(`📊 Test Summary: ${successCount} successful, ${errorCount} errors, ${warningCount} warnings`, 'info');
}
</script>
</body>
</html>