forked from Hitarth2510/Cloudify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-auth-flow.js
More file actions
66 lines (54 loc) · 1.95 KB
/
test-auth-flow.js
File metadata and controls
66 lines (54 loc) · 1.95 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
// Test the complete authentication flow
import fetch from 'node-fetch';
async function testAuthFlow() {
console.log('🧪 Testing Complete Authentication Flow...\n');
// Step 1: Login
console.log('1️⃣ Logging in...');
try {
const loginResponse = await fetch('http://localhost:3000/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'ravi@example.com',
password: 'password123'
})
});
const loginData = await loginResponse.json();
console.log('Login Status:', loginResponse.status);
if (loginResponse.status !== 200) {
console.log('❌ Login failed:', loginData);
return;
}
console.log('✅ Login successful!');
// Get cookies from login response
const cookies = loginResponse.headers.get('set-cookie');
console.log('🍪 Cookies received:', cookies);
// Step 2: Check auth status with cookies
console.log('\n2️⃣ Checking authentication status...');
const authResponse = await fetch('http://localhost:3000/api/debug/auth', {
method: 'GET',
headers: {
'Cookie': cookies || ''
}
});
const authData = await authResponse.json();
console.log('Auth Status:', authResponse.status);
console.log('Auth Data:', JSON.stringify(authData, null, 2));
// Step 3: Try accessing dashboard endpoint
console.log('\n3️⃣ Testing dashboard access...');
const dashboardResponse = await fetch('http://localhost:3000/dashboard', {
method: 'GET',
headers: {
'Cookie': cookies || ''
},
redirect: 'manual' // Don't follow redirects automatically
});
console.log('Dashboard Status:', dashboardResponse.status);
console.log('Dashboard Headers:', Object.fromEntries(dashboardResponse.headers.entries()));
} catch (error) {
console.error('❌ Test failed:', error.message);
}
}
testAuthFlow();