@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
} ) ;
10
10
} ;
11
11
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
12
- exports . addQuestion = exports . updateQuestion = exports . deleteQuestion = exports . db = void 0 ;
12
+ exports . isValidToken = exports . addQuestion = exports . updateQuestion = exports . deleteQuestion = exports . db = void 0 ;
13
13
const app_1 = require ( "firebase/app" ) ;
14
14
const firestore_1 = require ( "firebase/firestore" ) ;
15
15
const firebase_config_1 = require ( "../firebase/firebase.config" ) ;
@@ -61,3 +61,24 @@ function addQuestion(question) {
61
61
} ) ;
62
62
}
63
63
exports . addQuestion = addQuestion ;
64
+ function isValidToken ( token ) {
65
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
66
+ try {
67
+ const q = ( 0 , firestore_1 . query ) ( ( 0 , firestore_1 . collection ) ( exports . db , "users" ) ) ;
68
+ const querySnapshot = yield ( 0 , firestore_1 . getDocs ) ( q ) ;
69
+ const tokens = new Set ( ) ;
70
+ querySnapshot . forEach ( ( doc ) => {
71
+ const user = doc . data ( ) ;
72
+ tokens . add ( user . token ) ;
73
+ } ) ;
74
+ if ( tokens . has ( token ) ) {
75
+ return Promise . resolve ( true ) ;
76
+ }
77
+ return Promise . resolve ( false ) ;
78
+ }
79
+ catch ( error ) {
80
+ return Promise . reject ( error ) ;
81
+ }
82
+ } ) ;
83
+ }
84
+ exports . isValidToken = isValidToken ;
0 commit comments