Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check authentication middleware change on firebase authorization have error: UnhandledPromiseRejectionWarning #4

Closed
knockknockxo opened this issue May 1, 2020 · 1 comment

Comments

@knockknockxo
Copy link

knockknockxo commented May 1, 2020

Please help, any idea how to solve? thx

// @Dependencies
const { AuthenticationError } = require('apollo-server-express')
const admin = require("../Server/client")

module.exports = async (context) => {
// @Header
const header = context.req.headers.authorization

// @validate
if(!header)
    throw new Error('Musí sa uviesť hlavička overenia')

// @token
const token = header.split('Bearer ')[1]

// @validate
if(!token)
    throw new Error('Musí sa uviesť hlavička overenia')


try {
    // @auth
    const auth = await admin.auth().verifyIdToken(token)

    // @user
    const user = await admin.firestore()
        .collection('users')
        .where('id', '==', auth.uid)
        .limit(1)
        .get()

    return user.docs[0].data()
}
catch(error)
{
    throw new AuthenticationError(error)
}

}

@knockknockxo
Copy link
Author

Miss me await XO

Mutation: {
async createPost(_, { body }, context) {
try {
// @user
const user = await auth(context)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant