After user signs in on my Android App with Firebase I want to send the Firebase Token as a String param via GraphQL Mutation. Then receive it on my Express.js API inside the GraphQL mutation resolver and verify the token with the Firebase Admin SDK.
I have no idea if this is the correct way, all I want is to get the UID from the Token and check with Prisma if the UID is already existing on my MySQL User Table, if not then create a new user.
This should be done whenever the user inside the app uploads a new file, likes a post, comments etc.
I have absolutely no Idea if this is the way to do it.
Here is my Firebase Object (firebaseApp.js):
const admin = require('firebase-admin')
const serviceAccount = require("./.firebase/service-account.json");
const firebaseApp =
global.firebaseApp ??
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
})
// store on global object so we can reuse it if we attempt
// to initialize the app again
global.firebaseApp = firebaseApp
Here is my Mutation Resolver:
const db = require('../firebaseApp')
module.exports = {
Mutation: {
authenticateUser: async (parent, { token }) => {
db.auth().verifyIdToken(token)
.then((decodedToken) => {
const uid = decodedToken.uid;
return {
message: "User is authenticated: " + uid
}
})
.catch((error) => {
return {
message: "User is not authenticated: "
}
});
}
}
}
Here is the output when I try to send a token with the mutation:
db.auth is not a function
I have the strong feeling that I have a big misconception in my head and that this is aboslutely not the way to do it, I literally cannot find anything on the internet which explains this using my tech stack (Apollo GraphQL, Node.js, Prisma) Would appreciate some help