File tree 1 file changed +17
-2
lines changed
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,26 @@ import admin from "firebase-admin";
2
2
3
3
const test = async ( req , res ) => {
4
4
if ( ! admin . apps . length ) {
5
- admin . initializeApp ( ) ;
5
+ admin . initializeApp ( {
6
+ credential : admin . credential . cert ( {
7
+ projectId : "next-on-netlify-firebase" ,
8
+ clientEmail : process . env . FIREBASE_CLIENT_EMAIL ,
9
+ // Need to un-escape linebreaks from private key.
10
+ // See: https://stackoverflow.com/a/50376092/6451879
11
+ privateKey : process . env . FIREBASE_PRIVATE_KEY . replace ( / \\ n / g, "\n" ) ,
12
+ } ) ,
13
+ databaseURL : "https://next-on-netlify-firebase.firebaseio.com" ,
14
+ } ) ;
6
15
console . log ( "initialized!" ) ;
7
16
}
8
17
9
- return res . json ( { result : "success" } ) ;
18
+ // Fetch all users
19
+ const dbRef = admin . database ( ) . ref ( ) ;
20
+ const usersRef = dbRef . child ( "users" ) ;
21
+ const usersQuery = await usersRef . once ( "value" ) ;
22
+ const users = usersQuery . val ( ) ;
23
+
24
+ return res . json ( { users } ) ;
10
25
} ;
11
26
12
27
export default test ;
You can’t perform that action at this time.
0 commit comments