-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetToken.js
More file actions
41 lines (35 loc) · 1.49 KB
/
Copy pathgetToken.js
File metadata and controls
41 lines (35 loc) · 1.49 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
import { initializeApp } from 'firebase/app';
import { getAuth, signInWithEmailAndPassword, signOut, connectAuthEmulator } from 'firebase/auth';
// Firebase config (minimal for emulator)
const firebaseConfig = {
apiKey: "AIzaSyAQjx1c8Dt8kaKIvli1FcYPHuzTb2ZEPj8",
authDomain: "speakbridge-k23.firebaseapp.com",
projectId: "speakbridge-k23",
storageBucket: "speakbridge-k23.firebasestorage.app",
messagingSenderId: "1092663954272",
appId: "1:1092663954272:web:4adaafce0304a6bd2c6c05",
measurementId: "G-HM921GSVBL"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
// Đăng xuất trước (để đảm bảo token mới hoàn toàn)
console.log('🚪 Đang đăng xuất...');
await signOut(auth);
// Đăng nhập lại
console.log('🔐 Đang đăng nhập lại...');
const userCredential = await signInWithEmailAndPassword(
auth,
'bmquan.gd@gmail.com',
'adminpassword'
);
// Lấy token và claims (force refresh để có claims mới nhất)
const idToken = await userCredential.user.getIdToken(true);
const tokenResult = await userCredential.user.getIdTokenResult(true);
console.log('Token:', idToken);
console.log('\n📋 Claims:');
console.log('- UID:', tokenResult.claims.user_id);
console.log('- Email:', tokenResult.claims.email);
console.log('- Role:', tokenResult.claims.role || 'No role set');
console.log('- Admin:', tokenResult.claims.admin || false);
console.log('\n🔐 All Custom Claims:', JSON.stringify(tokenResult.claims, null, 2));