-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-auth.js
More file actions
53 lines (44 loc) · 1.71 KB
/
test-auth.js
File metadata and controls
53 lines (44 loc) · 1.71 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
// Test script for authentication flow
// Run with: node test-auth.js
const axios = require('axios');
async function testAuth() {
const baseURL = 'http://localhost:3000';
console.log('Testing authentication flow...\n');
// Test 1: Check if server is running
try {
const checkResponse = await axios.get(`${baseURL}/auth/check`);
console.log('✓ Server is running');
console.log(' Initial auth status:', checkResponse.data);
} catch (error) {
console.log('✗ Server is not running or /auth/check failed');
console.log(' Error:', error.message);
return;
}
// Test 2: Attempt login
console.log('\nAttempting login with test credentials...');
try {
const loginResponse = await axios.post(`${baseURL}/auth/login`, {
username: 'testuser',
password: 'testpass'
}, {
withCredentials: true,
headers: {
'Content-Type': 'application/json'
}
});
console.log('✓ Login request completed');
console.log(' Response:', loginResponse.data);
// Test 3: Check auth status after login
const checkAfterLogin = await axios.get(`${baseURL}/auth/check`, {
withCredentials: true
});
console.log('\n✓ Auth check after login');
console.log(' Auth status:', checkAfterLogin.data);
} catch (error) {
console.log('✗ Login failed');
console.log(' Status:', error.response?.status);
console.log(' Error:', error.response?.data || error.message);
}
}
console.log('Make sure you have set DEV_MODE=true in your .env file for testing\n');
testAuth();