Skip to content

Instantly share code, notes, and snippets.

@litewarp
Last active November 2, 2022 13:37
Show Gist options
  • Save litewarp/abdcfc991fa652605ab220b4dcbef01c to your computer and use it in GitHub Desktop.
Save litewarp/abdcfc991fa652605ab220b4dcbef01c to your computer and use it in GitHub Desktop.
Neo4j GraphQL Auth Workaround
export const neoSchema = new Neo4jGraphQL({
typeDefs,
resolver,
config: {
jwt: {
// create your own secret
secret: process.env.JWT_SECRET as string,
}
}
})
import jwt from 'jsonwebtoken'
const server: ApolloServer = new ApolloServer({
schema,
context: async ({ req }) => {
const { authorization } = req.headers
const token = authorization ? authorization.split(' ')[1] : undefined
// this example uses firebaseAuth, but any decoded JWT object can be used here.
// the shape of the decodedIdToken can be found here:
// https://firebase.google.com/docs/reference/admin/node/admin.auth.DecodedIdToken
try {
const decodedIdToken = await firebase.auth().verifyIdToken(token)
const newJWT = jwt.sign(decodedIdToken, process.env.JWT_SECRET as string)
req.headers.authorization = `Bearer ${newJWT}`
} catch (err) {
req.headers.authorization = ''
}
return { req, driver, ogm }
}
})
...
@Maadhav
Copy link

Maadhav commented Nov 2, 2022

Is this the most proficient way of integrating Firebase auth and neo4j-graphql together? Did you face any issues with this approach recently with this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment