59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
// Test authentication và ppoint service
|
|
// Chạy script này trong browser console tại http://localhost:3001
|
|
|
|
console.log('🔍 Testing Authentication...');
|
|
|
|
// 1. Check localStorage for tokens
|
|
const authToken = localStorage.getItem('auth_token');
|
|
const refreshToken = localStorage.getItem('refresh_token');
|
|
const authTokenAlt = localStorage.getItem('authToken');
|
|
|
|
console.log('📋 Token Status:');
|
|
console.log('- auth_token:', authToken ? '✅ Found' : '❌ Missing');
|
|
console.log('- refresh_token:', refreshToken ? '✅ Found' : '❌ Missing');
|
|
console.log('- authToken (alt):', authTokenAlt ? '✅ Found' : '❌ Missing');
|
|
|
|
if (!authToken && !authTokenAlt) {
|
|
console.log('❌ No authentication token found!');
|
|
console.log('💡 Please login first or set token manually:');
|
|
console.log(`
|
|
// Set token manually:
|
|
localStorage.setItem('auth_token', 'your-jwt-token-here');
|
|
|
|
// Or login via API:
|
|
fetch('http://localhost:7001/api/auth/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
email: 'hongochai10@icloud.com',
|
|
password: 'Hai@2025'
|
|
})
|
|
}).then(r => r.json()).then(data => {
|
|
if (data.success) {
|
|
localStorage.setItem('auth_token', data.data.tokens.accessToken);
|
|
localStorage.setItem('refresh_token', data.data.tokens.refreshToken);
|
|
console.log('✅ Token set successfully!');
|
|
}
|
|
});
|
|
`);
|
|
} else {
|
|
console.log('✅ Token found! Testing PPoint Service...');
|
|
|
|
// Test ppoint service
|
|
import('../../src/lib/ppoint.service.js').then(module => {
|
|
const ppointService = new module.PPointService();
|
|
|
|
ppointService.getUserBalance()
|
|
.then(balance => {
|
|
console.log('✅ PPoint Service working!');
|
|
console.log('💰 Balance:', balance);
|
|
})
|
|
.catch(error => {
|
|
console.error('❌ PPoint Service error:', error);
|
|
console.log('🔍 Error details:', error.message);
|
|
});
|
|
}).catch(error => {
|
|
console.error('❌ Failed to import ppoint service:', error);
|
|
});
|
|
}
|