1- import * as path from ' path'
2- import * as admin from ' firebase-admin'
3- import { required } from ' ./utils'
1+ import * as path from " path" ;
2+ import * as admin from " firebase-admin" ;
3+ import { required } from " ./utils" ;
44
55export default class FirebaseAuthAdapter {
6-
7- constructor ( ) {
8- admin . initializeApp ( {
9- credential : admin . credential . cert ( this . credentials ( ) )
10- } , "auth" )
11- }
6+ constructor ( ) {
7+ admin . initializeApp (
8+ {
9+ credential : admin . credential . cert ( this . credentials ( ) ) ,
10+ } ,
11+ "auth"
12+ ) ;
13+ }
1214
13- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14- async validateAuthData ( authData : { access_token : string ; id : string } , options : unknown ) : Promise < void > {
15- try {
16- const decodedToken = await admin . app ( 'auth' ) . auth ( ) . verifyIdToken ( authData . access_token )
17- if ( decodedToken && decodedToken . uid === authData . id ) {
18- return
19- }
20- throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , 'Firebase auth not found for this user.' )
21- }
22- catch ( error ) {
23- throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , 'Firebase auth is invalid for this user.' )
24- }
15+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16+ async validateAuthData (
17+ authData : { access_token : string ; id : string } ,
18+ options : unknown
19+ ) : Promise < void > {
20+ try {
21+ const decodedToken = await admin
22+ . app ( "auth" )
23+ . auth ( )
24+ . verifyIdToken ( authData . access_token ) ;
25+ if ( decodedToken && decodedToken . uid === authData . id ) {
26+ return ;
27+ }
28+ throw new Parse . Error (
29+ Parse . Error . OBJECT_NOT_FOUND ,
30+ "Firebase auth not found for this user."
31+ ) ;
32+ } catch ( error ) {
33+ throw new Parse . Error (
34+ Parse . Error . OBJECT_NOT_FOUND ,
35+ "Firebase auth is invalid for this user."
36+ ) ;
2537 }
38+ }
2639
27- validateAppId ( ) : Promise < void > {
28- return Promise . resolve ( )
29- }
40+ validateAppId ( ) : Promise < void > {
41+ return Promise . resolve ( ) ;
42+ }
3043
31- private credentials ( ) : admin . ServiceAccount {
32- const data = required ( ' FIREBASE_SERVICE_ACCOUNT' )
44+ private credentials ( ) : admin . ServiceAccount {
45+ const data = required ( " FIREBASE_SERVICE_ACCOUNT" ) ;
3346
34- try {
35- return JSON . parse ( data ) ;
36- } catch ( e ) {
37- return require ( path . resolve ( '.' , data ) )
38- }
47+ try {
48+ return JSON . parse ( data ) ;
49+ } catch ( e ) {
50+ return require ( path . resolve ( "." , data ) ) ;
3951 }
40- }
52+ }
53+ }
0 commit comments