Skip to content

Instantly share code, notes, and snippets.

View marekpiechut's full-sized avatar
💭
👨‍💻Programming or playing 🎸

Marek Piechut marekpiechut

💭
👨‍💻Programming or playing 🎸
View GitHub Profile
@marekpiechut
marekpiechut / sublime-medium.js
Last active January 21, 2019 12:56
Authentication and Authorization in NodeJS GraphQL API
Query: {
templates: requiresLogin((parent, args, { user }) => {
return service.fetchForUser(user.uuid)
}),
}
@marekpiechut
marekpiechut / sublime-medium.js
Last active January 21, 2019 12:56
Authentication and Authorization in NodeJS GraphQL API
const requiresLogin = resolver => (parent, args, context, info) => {
if (context.user && context.user.role === 'MEMBER') {
return resolver(parent, args, context, info)
} else {
throw new AuthenticationError('Unauthorized')
}
}
@marekpiechut
marekpiechut / sublime-medium.js
Last active January 21, 2019 12:56
Authentication and Authorization in NodeJS GraphQL API
Query: {
templates: (parent, args, { user }) => {
if (user && user.role === 'MEMBER') {
return service.fetchForUser(user.uuid)
} else {
throw new AuthenticationError('No Access!')
}
},
}
@marekpiechut
marekpiechut / sublime-medium.js
Last active January 21, 2019 12:56
Authentication and Authorization in NodeJS GraphQL API
const { AuthenticationError } = require('apollo-server-express')
const apollo = new ApolloServer({
...schema,
context: ({ req }) => {
const { user } = req
if (!user || user.role !== 'MEMBER') {
throw new AuthenticationError('No Access!')
} else {
return {
@marekpiechut
marekpiechut / sublime-medium.js
Last active January 21, 2019 12:56
Authentication and Authorization in NodeJS GraphQL API
const apollo = new ApolloServer({
...schema,
context: ({ req }) => ({
user: req.user,
}),
})
@marekpiechut
marekpiechut / sublime-medium.js
Last active January 21, 2019 12:56
Authentication and Authorization in NodeJS GraphQL API
app.use(passport.initialize())
app.use(passport.session())
const apollo = new ApolloServer(schema)
apollo.applyMiddleware({ app })
<root>
<child>
<grandchild>
Some text
</grandchild>
</child>
</root>
function testFunction() {
console.log('just log me1!');
return 32;
}
<root>
<child>
<grandchild>
Some text
</grandchild>
</child>
</root>
function testFunction() {
console.log('just log me!');
return 32;
}