-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-auth-direct.ts
More file actions
51 lines (40 loc) · 1.6 KB
/
test-auth-direct.ts
File metadata and controls
51 lines (40 loc) · 1.6 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
import { chromium } from 'playwright';
async function testLoginDirect() {
console.log('🚀 Testing authentication DIRECTLY on port 3000...\n');
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
try {
console.log('1️⃣ Making login request directly to API...');
const response = await page.request.post('http://localhost:3000/api/auth/sign-in/email', {
data: {
email: 'test@t.com',
password: '123456',
},
headers: {
'Content-Type': 'application/json',
},
});
console.log(`\n📥 Login Response Status: ${response.status()}`);
const setCookies = response.headersArray().filter(h => h.name.toLowerCase() === 'set-cookie');
console.log('\n🍪 Set-Cookie headers:');
setCookies.forEach(h => console.log(` ${h.value}`));
// Now check /me with the same context
console.log('\n2️⃣ Checking /me endpoint...');
const meResponse = await page.request.get('http://localhost:3000/api/auth/me');
console.log(`\n📥 /me Response Status: ${meResponse.status()}`);
const meData = await meResponse.json();
console.log('📄 /me Response:', JSON.stringify(meData, null, 2));
if (meData.user) {
console.log('\n✅ SUCCESS! Direct API auth works!');
} else {
console.log('\n❌ FAILED! Even direct API returns null');
}
await page.waitForTimeout(5000);
} catch (error) {
console.error('\n❌ Error:', error);
} finally {
await browser.close();
}
}
testLoginDirect().catch(console.error);