Files
pos-system/apps/client-example/scripts/developers/debug-token.js

84 lines
2.8 KiB
JavaScript

// Debug script để kiểm tra token trong localStorage
// Chạy trong browser console tại http://localhost:3001
// KHÔNG chạy với node command!
console.log('🔍 Debug Token Storage...');
// Check if running in browser
if (typeof window === 'undefined') {
console.error('❌ Script này phải chạy trong browser console, không phải Node.js!');
console.log('💡 Hướng dẫn:');
console.log('1. Mở browser tại http://localhost:3001');
console.log('2. Mở Developer Console (F12)');
console.log('3. Copy và paste script này vào console');
process.exit(1);
}
// 1. Kiểm tra tất cả localStorage keys
console.log('📋 All localStorage keys:');
Object.keys(localStorage).forEach(key => {
const value = localStorage.getItem(key);
console.log(`- ${key}:`, value ? `${value.substring(0, 50)}...` : 'null');
});
// 2. Kiểm tra các key có thể chứa token
const possibleKeys = [
'auth_token',
'authToken',
'token',
'access_token',
'accessToken',
'jwt_token',
'jwtToken',
'authToken',
'user_token',
'session_token'
];
console.log('🔑 Checking possible token keys:');
possibleKeys.forEach(key => {
const value = localStorage.getItem(key);
if (value) {
console.log(`✅ Found in ${key}:`, value.substring(0, 50) + '...');
} else {
console.log(`❌ Not found in ${key}`);
}
});
// 3. Kiểm tra sessionStorage
console.log('📋 All sessionStorage keys:');
Object.keys(sessionStorage).forEach(key => {
const value = sessionStorage.getItem(key);
console.log(`- ${key}:`, value ? `${value.substring(0, 50)}...` : 'null');
});
// 4. Kiểm tra cookies
console.log('🍪 All cookies:');
document.cookie.split(';').forEach(cookie => {
console.log(`- ${cookie.trim()}`);
});
// 5. Test manual token setting
console.log('🧪 Test manual token setting...');
const testToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbWgxZ2drMXgwMDAxZnZldHVoNWF1NzZpIiwiZW1haWwiOiJob25nb2NoYWkxMEBpY2xvdWQuY29tIiwib3JnYW5pemF0aW9uSWQiOm51bGwsInJvbGVzIjpbXSwicGVybWlzc2lvbnMiOltdLCJpYXQiOjE3NjEyODIyNDgsImV4cCI6MTc2MTM2ODY0OH0.h13MLTT35w7XIz1oz2y0tBJ4BQ0-NpqkbDRqcgtls3A';
localStorage.setItem('auth_token', testToken);
console.log('✅ Test token set in localStorage');
// 6. Test ppoint service với token
console.log('🧪 Testing PPoint Service with token...');
import('../../src/lib/ppoint.service.js').then(module => {
const ppointService = new module.PPointService();
ppointService.getUserBalance()
.then(balance => {
console.log('✅ PPoint Service working with token!');
console.log('💰 Balance:', balance);
})
.catch(error => {
console.error('❌ PPoint Service still failing:', error);
});
}).catch(error => {
console.error('❌ Failed to import ppoint service:', error);
});