Last active
November 2, 2022 13:37
-
-
Save litewarp/abdcfc991fa652605ab220b4dcbef01c to your computer and use it in GitHub Desktop.
Neo4j GraphQL Auth Workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const neoSchema = new Neo4jGraphQL({ | |
typeDefs, | |
resolver, | |
config: { | |
jwt: { | |
// create your own secret | |
secret: process.env.JWT_SECRET as string, | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
} | |
}) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?