Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 078275d

Browse files
committed
Fix firebase and parse initialization
1 parent 922881b commit 078275d

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"lib"
4646
],
4747
"dependencies": {
48+
"parse": "^2.12.0",
4849
"firebase-admin": "^8.10.0",
4950
"parse-cloud-image": "^1.0.0"
5051
}

src/FirebaseAuthAdapter.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,31 @@ import * as admin from 'firebase-admin'
33
import { required } from './utils'
44

55
export default class FirebaseAuthAdapter {
6-
7-
private firebase: admin.app.App
8-
6+
97
constructor() {
10-
this.firebase = admin.initializeApp({
11-
credential: admin.credential.cert(this.credentials()),
12-
databaseURL: required('FIREBASE_DATABASE_URL')
8+
admin.initializeApp({
9+
credential: admin.credential.cert(this.credentials())
1310
}, "auth")
1411
}
1512

1613
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1714
async validateAuthData(authData: { access_token: string; id: string }, options: unknown): Promise<void> {
1815
try {
19-
const decodedToken = await this.verifyIdToken(authData.access_token)
16+
const decodedToken = await admin.app('auth').auth().verifyIdToken(authData.access_token)
2017
if (decodedToken && decodedToken.uid === authData.id) {
2118
return
2219
}
2320
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Firebase auth not found for this user.')
2421
}
2522
catch (error) {
26-
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Firebase auth is invalid for this user.')
23+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, error)
2724
}
2825
}
2926

3027
validateAppId(): Promise<void> {
3128
return Promise.resolve()
3229
}
3330

34-
verifyIdToken(token: string): Promise<admin.auth.DecodedIdToken> {
35-
return this.firebase.auth().verifyIdToken(token)
36-
}
37-
3831
private credentials(): admin.ServiceAccount {
3932
const data = required('FIREBASE_SERVICE_ACCOUNT')
4033

src/FirebaseStorageAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as path from 'path'
22
import { Request, Response } from 'express';
3-
import { Config } from 'parse';
43
import { required, optional, persists, isImage, generateThumbnails } from './utils';
54
import * as admin from 'firebase-admin';
65
import { Bucket } from '@google-cloud/storage';
6+
import { Config } from 'parse/node';
77

88
export interface File {
99
filename: string;

0 commit comments

Comments
 (0)